Git shortcuts

Posted 2014-01-03 05:03 PM GMT

Here are a few command line shortcuts I have created to use Git faster. Put these in your dot-files, and you will type much less when using Git.

First, download .git-completion.bash and put it in your home directory.

Next, put this line in .bash_profile

source ~/.git-completion.bash

Finally, put this stuff in ~/.bash_aliases

#Git stuff

# use .git-completion.bash to allow tab # completion of branch names when using gch __git_complete gch _git_checkout

# gs to show git status alias gs='git status'

# gd to show git diff of uncommitted changes alias gd='git diff'

# gb to show the list of branches alias gb='git branch'

# gmm to merge master into the current branch alias gmm='git merge master'

# gch to checkout master or a given branch # example: # gch my-other-branch function gch { if [ -z "$1" ]; then git checkout master else git checkout $1 fi }

# gco to check out a new branch based on master function gco { git checkout -b $1 master }

# gc to commit, optionally with a message function gc { if [ -z "$1" ]; then git commit else git commit -m "$1" fi }

Go forth, branch and merge with ease.