Visual Git History Log in Terminal Window

Git Log

My friend Joshua Kalis just showed me this cool trick which allows you to see a visual history (e.g. merges) in your terminal. Normally I bust out GitX-L every time I want to see a visual git history (this is akin to running Photoshop to select a color), but this technique is much more convenient.

Edit your ~/.gitconfig file, and add the following lines:

[alias]
    lg = log --graph --pretty=format:'%C(red)%h%C(reset) -%C(yellow)%d%C(reset) %s %C(green)(%cr) %C(blue)<%an>%C(reset)' --abbrev-commit --date=relative

This will add a convenient git alias to your repertoire, in this case lg (accessible by using git lg).

Personally, I like having even shorter aliases, so I edited my ~/.bash_profile file and added the following:

alias glg='git lg'

This lets me simply type glg and get a pretty output.

Alternatively, you could just add this to your bash profile and get the same effect:

alias glg='git log --graph --pretty=format:'%C(red)%h%C(reset) -%C(yellow)%d%C(reset) %s %C(green)(%cr) %C(blue)<%an>%C(reset)' --abbrev-commit --date=relative'
Tags: #git
Thomas Hunter II Avatar

Thomas is the author of Advanced Microservices and is a prolific public speaker with a passion for reducing complex problems into simple language and diagrams. His career includes working at Fortune 50's in the Midwest, co-founding a successful startup, and everything in between.