Beautiful Git Log with Bash Alias in Linux

F. Ana. D
2 min readSep 21, 2018

As a web developer, checking git log is a daily routine. But if we use simple git log without any option, the result is using too much space with their layout.

So what if we can create our git log to give beautiful output like this?

To get git log beautifully like that, we need to add options on git log command, like this

git log --pretty=format:'%C(yellow)%h %Cred%ad %Cblue%an%Cgreen%d %Creset%s' --date=short

But, do we need to write all that long command every time we want to see a beautiful git log? That’s will be a troublesome. So this is when we need to use bash alias.

Bash Aliases

Bash alias is essentially nothing more than a keyboard shortcut, an abbreviation, a means of avoiding typing a long command sequence.

That’s exactly what we need! Now, how to make bash alias for that? Let me tell you how to do it for Linux.

The first thing to do is create a~/.bash_aliases (if it’s not already) with touch ~/.bash_aliases . Open it, and insert the alias definition there. For now, insert this alias:

alias gitlog="git log --pretty=format:'%C(yellow)%h %Cred%ad %Cblue%an%Cgreen%d %Creset%s' --date=short"

Save it and close the file. Next step is open ~/.bashrc and add or uncomment the following lines (if it is not already).

if [ -f ~/.bash_aliases ]; then
. ~/.bash_aliases
fi

Save it and close the file. Now, the alias is not yet working as expected until you re-sourcing the ~/.bashrc or restart the terminal. So we resourcing the ~/.bashrc with this command: . ~/.bashrc

Now, when you write gitlog , the bash will run this long command for you

git log --pretty=format:'%C(yellow)%h %Cred%ad %Cblue%an%Cgreen%d %Creset%s' --date=short

That’s beautiful, right?

--

--

F. Ana. D

Software Engineer — [Note: English is not my first language so please bear with me]