Helpful Git aliases

Git is a fast distributed version control system. If you haven’t heard of git, you can read all about it at http://git-scm.com. Here are some convenient aliases I’ve created to speed up Git usage. You can put these directly in your .bashrc or .bash_aliases file for unix based systems. First, some basic commands that I find myself typing often.

1
2
3
4
5
6
# Git shortcuts
alias gs='git status'
alias gc='git commit -m'
alias gca='git commit --amend'
alias gfa='git fetch --all'
alias gm='git merge'

When working locally against a remote repository, it is very helpful to create both a local branch and an upstream branch. Then set the local branch to track your remote branch. Assuming your remote is called ‘origin’, the following function does this quite nicely.

1
2
3
4
5
6
7
8
9
10
11
# Make a branch.
function gb() {
  if [ -z "$1" ]; then
    echo "ERROR: You must provide a branch name."
    exit
  fi
  git checkout -b $1
  git push origin $1
  git branch --set-upstream $1 origin/$1
  echo "Done."
}

Similar to creating a branch, it is helpful to be able to delete a branch both locally and from the remote repository.

1
2
3
4
5
6
7
8
9
10
# Delete a branch.
function gd() {
  if [ -z "$1" ]; then
    echo "ERROR: You must provide a branch name."
    exit
  fi
  git branch -D $1
  git push origin :$1
  echo "Done."
}
Tweet

Comments:

Subscribe & Contact

Know how to listen, and you will profit even from those who talk badly.
~ Plutarch ~