Juicy lil' bytes

Git Logs With Color and Graphs

Want to add some color to your Git log? Check out this git log configuration that gives you one commit per line, a commit graph, abbreviated commit ID’s, relative dates, & commit author all bundled up in color coordinated text.

Git Logs with Graphs and Color

Navigate to your git initialized directory (that includes previous commits) and use this command:

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

Source: Patryk Małek in comments on this Coderwall post by Filipe Kiss

and your output will look like this: image

Conserve ATP, Make a Git Alias

Save yourself keystrokes by creating a git alias so that you can open your colorful new log style as if you were using any built-in git command.

Method 1

Filipe and Patryk demonstrate how to configure the git alias “lg” in the thread. For the above command, it looks like this:

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

Make sure that you keep that --global switch if you want this included as part of your global git configuration.

To change the alias name, modify the alias.lg string with the alias that you’d like to use. For example, to call it purtylog you would change it to alias.purtylog.

Method 2

Alternatively, you can add your new alias to your ~/.gitconfig file. Open the file in an editor and (if you have not already done so) add an [alias] section to the file with the following alias definition for lg:

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

Use It

With both methods, you then view your new log style with the following command (using your new alias):

git lg