My favorite git log explained

I love when tools let you customize every little bit to fit you and your preferences. Git is brilliant in this way, and I've used this freedom to tweak different things within git.

One of those things are the log command:

git log --graph --all --pretty=format:'%C(yellow)%h -%C(auto)%d %C(bold cyan)%s %C(bold white)(%cr)%Creset %C(dim white)<%an>'  

This command creates the following output:

Now lets break it down!

My git log is built together by 3 flags:

  • --graf - Creates a text-based graphical representation of the commit history. The graph really increases the readability of the git history.

  • --all - Shows the history of all the branches instead of just the one you currently have checked out. Together with --graph, it gives a good overview of the branches and how they are related.

  • --pretty - Lets you format how the commits are going to be displayed. You have a lot of built-in formats, like oneline, short and medium, but to get full control of how the commit is displayed, you can use the format option.


To create a customized format for the commit messages, you have to combine placeholders to create a string that describes the format. The placeholders represent different information about the commit. I've used the following placeholders in my log command:

  • %h - abbreviated commit hash.
  • %d - shows the different branch names.
  • %s - adds the commit message.
  • %cr - one of many date placeholders. This particular one shows how long ago the commit was created.
  • %an - adds the author of the commit.
  • %C(...) - sets the color you define in the brackets
  • %Creset - resets the color

There's a lot more placeholders you can use. You can find them all in the the git-log Manual Page.

Alias it!

You don't want to type such a long command everytime you want to run your custom git log. To avoid that we can just create an alias.

git config --global alias.lg "log --graph --all --pretty=format:'%C(yellow)%h -%C(auto)%d %C(bold cyan)%s %C(bold white)(%cr)%Creset %C(dim white)<%an>'"  

Now you can just run git lg, then the log command will be executed.

Combine your alias with more flags

Even if you have created an alias, you can still add flags to your command. I often want to see what files have been affected by a commit. I then just add --stat after my git lg command, then I get a nice overview of the affected files and number of insertions/deletions:

If your want to explore the git log command further, take a look at the Manual Page and start experiment with the possibilities!

Enjoyed the post?

If you don't want to miss future posts, make sure to subscribe