Skip to content

Instantly share code, notes, and snippets.

@zdennis
Last active August 29, 2015 14:07
Show Gist options
  • Save zdennis/fe8e96109d95eab8e518 to your computer and use it in GitHub Desktop.
Save zdennis/fe8e96109d95eab8e518 to your computer and use it in GitHub Desktop.
gitconfig aliases
# +cbranch+ returns the current branch you are on
cbranch = !"git branch | grep '*' | cut -f2 -d' '"
# +open-url+ opens the home page for this repository
open-url = !"open `git remote show origin | grep 'Fetch URL' | ruby -e \"puts 'http://' + STDIN.read.scan(/Fetch URL: git@(.*)/).join.sub(':', '/').sub('.git','')\"`"
# +open-branch+ opens the current branch in your default browser
open-branch = !"open `git remote show origin | grep 'Fetch URL' | ruby -e \"puts 'http://' + STDIN.read.scan(/Fetch URL: git@(.*)/).join.sub(':', '/').sub('.git','') + \\\\\"/tree/#{%x|git cbranch|}\\\\\"\"`"
# +open-sha+ opens the current SHA in your default browser
open-sha = !"open `git remote show origin | grep 'Fetch URL' | ruby -e \"puts 'http://' + STDIN.read.scan(/Fetch URL: git@(.*)/).join.sub(':', '/').sub('.git','') + \\\\\"/commit/#{%x| git log -n1 --pretty=%H|}\\\\\"\"`"
# e.g. - https://github.com/account/repos/pull/new/chore/branch-name-here
open-pull = !"open `git remote show origin | grep 'Fetch URL' | ruby -e \"puts 'http://' + STDIN.read.scan(/Fetch URL: git@(.*)/).join.sub(':', '/').sub('.git','') + \\\"/pull/new/#{%x|git cbranch|}\\\"\"`"
# +add-ignore+ downloads ignore files from Github and adds them to your local
# .gitignore. TODO: This can be way awesomer.
add-ignore = !"g(){ url="https://raw.github.com/github/gitignore/master/$1.gitignore" ; curl --output /dev/null --silent --head --fail "$url" ; if [ $? -eq 0 ]; then curl "$url" >> .gitignore && echo "Appended .gitignore with $url" ; else echo "$url doesnt exist." ; fi ; }; g"
@drench
Copy link

drench commented Oct 9, 2014

I think you could avoid the piping & filtering in cbranch using this instead:

git symbolic-ref --short HEAD

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment