A Better Git Log

If you need to take a quick look at the recent commits to the current branch, a git log is going to get you there. However, as you start to do development that involves multiple branches, a simple git log is going to come up short. This is because, by default, git log only shows you the commit history of the current branch. To see the commits on another branch and how they relate to the current branch, you are going to have to switch between branches.

Fortunately, there are some flags that can be added to a git log command to reveal more information in one go. If we add both --graph and --all, we get a graph view that shows each branch as they relate to one another.

We can go a bit further by adding a few more flags that will show a concise, one-line graph that is easy to read:

$ git log --graph --all --oneline --decorate --color
* b9f7b9e (HEAD, master) Change how hello.rb works
* eb9b32e Add some comments
| * 04edc10 (another-branch) Add some usage information
| * 82bbe12 Change how hello.rb works
|/
* 1248770 Add hello.rb
* 984691c Initial commit

This is something we use everyday at Hashrocket with the git tree alias as part of our dotmatrix repository.

To do the same, just include the tree alias in the alias section of your .gitconfig file.

[alias]
  tree = log --graph --oneline --decorate --color --all 

Now enjoy that better git log.