Git

Show Git Tree in Terminal

The git log command is a useful command that allows you to look at Git commits history. However, this text-based log may not be preferred by most users, since the output can be very difficult and complex to visualize and interpret. A more visually appealing way to present this log is in the form of a Git tree. This article describes several methods that you can use to create a Git tree in the terminal in Ubuntu 20.04.

Methods of Showing the Git Tree in Ubuntu 20.04 Terminal

The following sections cover several different methods for displaying a Git tree in your terminal. Before attempting these methods, we will first navigate to our test project repository by running the following command:

cd /home/kbuzdar/simplegit-progit

You can provide your own path with the “cd” command, i.e., the location in which your test project repository currently exists.

After running this command, the path in your terminal will instantly change, as shown in the image below:

Method 1: Using the graph Flag with the git log Command

Once we have navigated to the test project repository, we will run the following command to show the Git tree in our Ubuntu 20.04 terminal:

git log --graph

Our Git project tree is shown in the image below:

Method 2: Using the oneline Flag with the git log Command

We can also create the Git tree in our terminal by running the following command:

git log --graph --oneline --all

Our Git project tree is shown in the image below:

Method 3: Using the pretty Flag with the git log Command

This is yet another method that to create the Git tree in your Ubuntu 20.04 terminal. You can create the Git tree using this method by running the following command:

git log --graph --pretty=oneline --abbrev-commit

Our Git project tree is shown in the image below:

Conclusion

This article showed you three different methods for creating a Git tree in your Ubuntu 20.04 terminal. A question that still might concern you is, “What is the difference between Method # 2 and Method # 3, because apparently both of them show the exact same output?” Well, this difference can only be seen if your Git log is rich enough, i.e., it contains a significant number of commits. If you perform both Method #2 and #3 on a Git project repository that contains enough commits, then you will see that the output of Method # 2 will be more technical, as it may contain some ASCII values; whereas, the output of Method # 3 will be more user-friendly, which would solely be due to using the “pretty” flag in that method.

About the author

Karim Buzdar

Karim Buzdar

Karim Buzdar holds a degree in telecommunication engineering and holds several sysadmin certifications. As an IT engineer and technical author, he writes for various web sites. He blogs at LinuxWays.