DEV Community

Cover image for Beautify Your Git Log with a Single Command
Pradumna Saraf
Pradumna Saraf

Posted on

Beautify Your Git Log with a Single Command

The standard git log command is functional, providing the necessary information, but it can come across as somewhat dull and verbose. What if there was a way to make the git log not just informative, but also visually appealing? Something like this:

Image description

Yes, it's entirely possible! And the good news is that we can achieve this by simply using a bunch of flags and subcommands. There's no need to install or download anything.

Here's the command:



git log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit --branches


Enter fullscreen mode Exit fullscreen mode

But typing this command every time could be tiresome. A solution to this is using Git aliases, which allow you to create shortcuts for lengthy commands. If you're unfamiliar with Git aliases, I recommend reading my recent article that dives into the topic:

Now, let's set up an alias for our beautiful git log command:



git config --global alias.lg "log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit --branches"


Enter fullscreen mode Exit fullscreen mode

Now you can invoke the beautified git log using a simpler git lg.

Top comments (10)

Collapse
 
markhu profile image
Mark • Edited

I love this. A terse variant is: git log --oneline --graph -n11
My fancy variants I've been using for years:

[alias]
        log2 = log -n2 --graph --pretty=format:'%C(auto,yellow)%h %C(auto,blue)%>(18,trunc)%ad %C(auto,green)%<(12,trunc)%aN %C(auto,reset)%s%C(auto,red)% gD% D'
        log9 = log -n9 --graph --pretty=format:'%C(auto,yellow)%h %C(auto,blue)%>(18,trunc)%ad %C(auto,green)%<(12,trunc)%aN %C(auto,reset)%s%C(auto,red)% gD% D'
        log11 = log -n11 --graph --pretty=format:'%C(auto,yellow)%h %C(auto,blue)%>(18,trunc)%ad %C(auto,green)%<(12,trunc)%aN %C(auto,reset)%s%C(auto,red)% gD% D'
Enter fullscreen mode Exit fullscreen mode
Collapse
 
robertobutti profile image
Roberto B.

Thank you for sharing!

When I need to take a look or have a quick overview of the commits, my git log is :

git log --pretty=format:'%s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit
Enter fullscreen mode Exit fullscreen mode
Collapse
 
bullbiased profile image
Bull

Amazing Blog

Collapse
 
ghadzhigeorgiev profile image
Georgi Hadzhigeorgiev

Superb, thank you very much!

Collapse
 
edenwheeler profile image
Eden Wheeler

Amazing Article.

Collapse
 
shersi32 profile image
Saeed H

Love it!

Collapse
 
fpalamour profile image
fpalamour

Nice tip! I'll definitely start using it!

Collapse
 
hitblast profile image
HitBlast

Amazing blog, definitely recommended for Git beginners, especially those who're trying to get their hands on advanced version control commands.

Collapse
 
visheshrwl profile image
Vishesh Rawal

Useful 💯💯

Collapse
 
shoodler profile image
Shantanu Shaji

Thanks, that's really helpful