If you are a sysadmin or developer that uses a lot of repos throughout the day, and you use Github, this little snippet will come in handy. No more opening a browser window and fumbling around trying to navigate to your repo. Just type gh anywhere inside your project path and a browser window will open your repo on Github.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# GH | |
# by Brock Angelo | |
# for Mac OSX & Unix | |
# https://gist.github.com/1917716 | |
# Description: when you are on the command line and want to open your project in Github, just type "gh". Latest version opens the current branch on github as well. | |
# | |
# SETUP: | |
# 1. Copy this snippet to ~/bin/gh | |
# 2. Make it executable by running: chmod +x ~/bin/gh | |
# 3. From the command line, inside your project, type gh and the browser window will open. | |
BRANCH=$(git branch | grep "*" | awk '{print $2}') | |
git remote -v | grep fetch | sed 's/\(.*github.com\)[:|/]\(.*\).git (fetch)/\2/' | awk -v BRANCH=$BRANCH {'print "https://github.com/" $1 "/tree/" BRANCH'} | xargs open |
For this to work, you’ll need to do two things:
- Copy the snippet to ~/bin/gh
- Make it executable by running: chmod +x ~/bin/gh
- Reload or restart your terminal, browse into a Github project, type gh and boom!