Jump to content

Show Git Tree in Terminal


Linux Hint

Recommended Posts

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.

word-image-279.png

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

word-image-280.png

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

word-image-281.png

Our Git project tree is shown in the image below:

word-image-282.png

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

word-image-283.png

Our Git project tree is shown in the image below:

word-image-284.png

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

word-image-285.png

Our Git project tree is shown in the image below:

word-image-286.png

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.

View the full article

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...