At work we used git backed by GitHub. After every
git push I open the browser, go to GitHub, and navigate to the branch.
While only a few clicks, I repeat this process many times a day. In lazy developer fashion I wanted to automate this process.
A Google search for open GitHub from command line yielded two promising results.
First, hub, which not only opened GitHub from the command line but wrapped
git entirely to provide even more features.
hub looked awesome, but went well-beyond my needs.
The second result was a bash function that generates your GitHub URL and uses the Mac OS
open command to launch the browser.
Unfortunately it didn’t work. Being just a few lines of code, I decided to fix the script. To honor the original author, I kept the same command name -
By simply typing
gh I can open the current branch in my repository on GitHub.
I also extended the original script with optional parameters for remote and branch. It follows a similar format as
gh [remote-name] [branch-name]
These default to origin and the current checked out branch, respectively.
Now I can open any repository and branch on GitHub from the command line with:
gh origin dev
gh on GitHub. Please send me a pull request with your additions.
comments powered by Disqus