Archive for March, 2017

Useful Git Aliases

Thursday, March 9th, 2017

When you use git often, it is helpful to implement some aliases for frequent commands. Git has config options to allow for shortening commands or allowing you to use a simple command instead of a line of text that is difficult to remember.

Some simple shortcuts:
To make checkout shorter

git config --global alias.co checkout

This will allow you to just type:

git co

To make status shorter:

 
git config --global alias.st status

This will let you see the log with branch indicators and a graph of the branches:

git config --global alias.mylog "log --pretty=format:'%h %s [%an]' --graph"

This is similar to the mylog alias but is useful on a color terminal as it will highlight useful items in the comments:

git config --global alias.lol "log --graph --decorate --pretty=oneline --abbrev-commit ==all"

The results will be the following lines in your .gitconfig file:

[alias]
        st = status
        co = checkout
        mylog = log --pretty=format:'%h %s [%an]' --graph
        lol = log --graph --decorate --pretty=oneline --abbrev-commit --all

Tags: