Skip to content

Instantly share code, notes, and snippets.

@motleytech
Created June 25, 2016 05:33
Show Gist options
  • Save motleytech/23dd719d484a19ea7b9535785d46ec6c to your computer and use it in GitHub Desktop.
Save motleytech/23dd719d484a19ea7b9535785d46ec6c to your computer and use it in GitHub Desktop.
git shortcuts and aliases

Here are some useful git config options for

  1. Displaying colors in status and diff outputs.
  2. Creating aliases and shortcuts for common git commands.
  3. Setting shortcuts from the command line itself.

First, create a ~/.gitconfig file for your user account, which will store the changes we are about to make.

touch ~/.gitconfig

To add color to git output, add the following to the file

[color]
  diff = auto
  status = auto
  branch = auto
  interactive = auto
  ui = true
  pager = true

I don't like typing git status every time that I have to check on my repo. git st should do it. Here is how to do that (and some more). Add the following to your ~/.gitconfig.

[alias]
  co = checkout
  ci = commit
  st = status
  br = branch
  hist = log --pretty=format:\"%h %ad | %s%d [%an]\" --graph --date=short
  type = cat-file -t
  dump = cat-file -p

Also, you can come up with even shorter shortcuts. You could add new aliases to your ~/.bashrc like alias gdiff='git diff' or alias gst='git status'.

And if you are in a hurry, you can always setup your shortcuts from the command line.

git config --global user.name username
git config --global user.email [email protected]
git config --global alias.co checkout
git config --global alias.st "status"
git config --global alias.stat "status"
git config --global alias.br branch
git config --global alias.wdiff "diff --color-words"
git config --global merge.tool diffuse
git config --global merge.summary true
git config --global difftool.prompt false
git config --global diff.tool diffuse
git config --global merge.tool diffuse
git config --global color.ui true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment