All Articles

Becoming more productive with git aliases

We all know in order to be more productive we have to do things quicker (ideally automate it) or we hire additional help. But not all scenarios are optimizable - like 9 women can’t deliver baby in a month. Fortunately we’re discussing tech here, so let’s leave biology out of this discussion.

Strictly IT speaking, in order to optimize our workflows we either build new tools or extend existing ones. So regarding git, I do not miss any features but I do wish for shorter commands and there’s a solution for this problem!

In GNU/Linux we do know a concept called shell aliases, which are just shortcuts for commands that you define them yourself. If you’re using Bash shell you’ll find them all under ~/.bash_aliases.

Here are my git aliases:

alias gbr='git branch'
alias gcane='git commit --amend --no-edit'
alias gcm='git commit -m'
alias gc='git checkout'
alias gcmn='git commit -n -m'
alias glo='git log --oneline'
alias gpr='git pull --rebase'
alias gprd='git pull --rebase origin develop'
alias grh='git rebase -i HEAD~2'
alias grv='git remote -v'
alias gs='git status'
alias gd='git diff'

Save it to ~/.bash_aliases and run source ~/.bash_aliases to load them and start using them right away.

There’s even better solution. You can use global .gitconfig, usually found under ~/.gitconfig and put git aliases there.

  br = branch
  cane = commit --amend --no-edit
  cm =  commit -m
  cmn = commit -n -m
  co = checkout
  d = diff
  last = log -1 HEAD
  lo = log --oneline -n 10
  pr = pull --rebase
  prd = pull --rebase develop
  rh = rebase -i HEAD~2
  rv = remote -v
  s = status

You can add them also by using git config command:

git config --global branch
git config --global "commit -m"

And then add only one alias to ~/.bash_aliases:

alias g=git

Simple problems, simple solutions.

Which (git) aliases do you use? Tweet me @kranjski