View The Git Commit Tree In Terminal

back to tech articles
Ubuntu 14.04.2 LTS, Git 1.9.1

Sometimes it’s super-useful to view the Git commit tree right in the terminal on the remote host. This can be achieved in several ways. I’m going to show you how we can get a simple coloured summary output of the state of the repo right in the terminal. Lastly we’ll add an alias to make future requests super-easy.

The Tree

We can use Git’s log feature to dig up old commits and spit them out. We can even do this in a decorative order if we add some parameters. First, let’s see the standard output;

1
$ git log

This will give us some expanded output, similar to the following:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
commit 7eaddaec9306993jdu02110071ed0477146717cd
Author: Jason <webmaster@commitit.now>
Date:   Thu Apr 16 20:29:42 2015 +0100

    Allowing to simmer now, garlic is in.

commit 532c7f4akdi3sfe7d3fcc045b99de10a6c02d65c
Author: Jason <webmaster@commitit.now>
Date:   Thu Apr 16 20:27:02 2015 +0100

    Smells amazing, time for a splash of white wine.

commit 2a89c4f3cca638f9debf4830b57fe3fca980cc03
Author: Jason <webmaster@commitit.now>
Date:   Thu Apr 16 20:25:47 2015 +0100

    Add some onions, and the seasoning, yummy.

commit a1a4e91b2f2e3k239sf456ecdd178d28340cb99a
Author: Jason <webmaster@commitit.now>
Date:   Thu Apr 16 20:24:25 2015 +0100

    Created the repo, let's get cooking!

As you can see, standard log gives us a detailed view of each commit in the history. While this is useful for some tasks, I’m more interested in getting a quick summary of the repo in a tree-like view, particularly the date, commit and commit message.

Let’s make this pretty by passing in some extra arguments.

1
$ git log --oneline --decorate --all --graph

Now we get a much nicer, decorative summary of what’s going on in the repo:

1
2
3
4
* 7eaddae (HEAD, master) Allowing to simmer now, garlic is in.
* 532c7f4 Smells amazing, time for a splash of white wine.
* 2a89c4f Add some onions, and the seasoning, yummy.
* a1a4e91 Created the repo, let's get cooking!

Bingo, that’s what we wanted. We can also see at a glance which branch the HEAD is pointing at. Now to add an alias and simplify future summaries!

Adding A Git Alias

We could add this to the repo’s .git/config file, but since we want this alias available at the user level, we’ll edit the file at ~/.gitconfig instead. You can create this if it doesn’t exist; Git will automatically include this file and any aliases it contains; sweet!

1
2
3
$ vi ~/.gitconfig
[alias]
        tree = log --oneline --decorate --all --graph

Save that and exit. You now have access to the tree alias in Git. You can execute this as simple as:

1
$ git tree

Conclusion

There are other ways to achieve this, and some admins prefer to get very detailed with the Git log. Hopefully this will be a good starting point for you!

Leave a Reply

Your email address will not be published. Required fields are marked *