Visual Git History Log in Terminal Window

Git Log
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'
Thomas Hunter II Avatar

Thomas has contributed to dozens of enterprise Node.js services and has worked for a company dedicated to securing Node.js. He has spoken at several conferences on Node.js and JavaScript, published a book on microservices, and is an organizer of Nodeschool SF.