View The Git Commit Tree In Terminal

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;

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:

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!

123

$ 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

$ gittree

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!