Making the most out of Git Log

In this video we are going to look at the git log command.

Git in general is vast. There really is a lot to learn. And whilst you don't need to know very many commands to get started, you shouldn't stop learning more about the available commands just because you know enough to get by.

As with most git commands there are a number of options that can be specified when using git log which make the output very configurable.

At its most basic, the git log command will show us the commit logs.

Whilst the default view is useful, personally I find that the output is a little too verbose for my liking. This is personal preference, of course.

Before I began exploring git log further than that simple command, I had found a workflow that suited my needs. I would commit my changes and push them up to a GitLab server where I could then use the 'Commits' section of the given repo to browse the log in a format that better suited my needs.

Whilst on GitLab, I also infrequently made use of the 'Network' view to enable a greater visualisation of the current project status.

Combined, these views made my life with git a lot more managable.

However, it turns out there is already a method of viewing your repo like this, and it's built right in to git.

git log --oneline --decorate --color --graph

It's well worth creating yourself an alias for this command as it's incredibly useful, if not a complete pain to remember / type out each time you need it.

I use ohmyzsh so this command is available as glog.

If you use ohmyzsh, or you would like to set up some similar aliases, then this list may help you further:

Alias Full Command
glg git log --stat --max-count = 10
glgg git log --graph --max-count = 10
glgga git log --graph --decorate --all
glo git log --oneline --decorate --color
glog git log --oneline --decorate --color --graph

Doubtless there are more options and combinations you may wish to include. I find the ohmyzsh cheatsheet particularly handy for learning about new commands like this.

Hidden Benefits

Learning another git command is great. As a developer there is always a ton of stuff to learn, and realistically not one of us can know it all.

Some skills, however, are more important than others.

We can Google for git log --oneline --decorate --color --graph should we need to. It's a concrete 'thing' that we can learn, commit to memory, or simply alias and never worry about it again.

The side affect to using this command is that suddenly our git commit history becomes immediately useful to us on the command line.

I no longer have to push my code to GitLab, open up a browser, browse to my repo, then have two tabs open - one for my commit messages, and another for my network diagram.

Instead, I can see everything on the command line.

But even better still is that my commit messages now are much more useful to me. Because the command opens up an immediate view, I'm more likely to use it. As I'm more likely to use it, I am more likely to care about the content of my commit message.

This is a big win for me.

As ever, it's an exercise in self improvement. I'm not there yet, but I have made a start down the right path. I hope you will consider doing the same.

Code For This Course

Get the code for this course.