Git

Unable to Show a Git Tree in Terminal

Git trees are the major component of Git that are frequently used to keep the record of tracked files in the blobs. Whenever users utilize the “git add” command to track the changes, Git creates a blob and adds the commit changes in the local repository. Sometimes, Git users want to view the Git branches and commits of these branches in the form of a tree without using the Git GUI version. However, if you are unable to show a Git tree in the Git terminal? Do not worry!

This blog will demonstrate the procedure to show a Git tree in the terminal.

How to Show a Git Tree in Terminal?

To show a Git tree in the terminal, first, open the Git repository. Next, utilize the “git log –graph” command or the “git log –oneline –graph –all” command to view the Git tree.

To show a Git tree in the terminal, check out the provided command.

Step 1: Launch Git Bash Terminal

Search for “Git Bash” in the Start menu to open the Git terminal:

Step 2: Open the Git Repository

Next, utilize the “cd” command to move to the Git repository:

$ cd "C:\Git\Test"

Step 3: Start File in Text Editor

Do some changes in the repository to add a new commit. For instance, we will modify the “test.txt” file by opening it in the default text editor through the provided command:

$ start Test.txt

Make some changes in the file and hit the “Ctrl+S” button to save modifications:

Step 4: Add Untracked Changes in Staging Environment

After that, add the untracked modifications in the staging environment through the “git add” command:

$ git add Test.txt

Verify whether the changes are added or not in the staging area using the “git status” command:

$ git status

It can be observed that the changes are successfully added to the tracking index:

Step 5: Commit Tracked Changes

Utilize the “git commit” command to save the tracked changes in the Git repository:

$ git commit -m "modifies Test file"

Step 6: Show Git Tree Using –graph Option

To view the latest commit in the form of a tree or to view the Git tree itself, utilize the “git log” command along with the “–graph” option:

$ git log --graph

Step 7: Show One-line Graph/Tree

To show the one-line graph or tree to view all branches along with commits, utilize the provided command:

$ git log --oneline --graph --all

Alternatively, users can utilize the “–pretty” flag to view the Git tree:

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

We have demonstrated how to show the Git tree in the Git terminal.

Conclusion

To show the Git tree in the terminal without using Gitk or any GUI version of Git, first, open the Git repository. Then, view the Git tree through the “$ git log –graph” or “$ git log –oneline –graph –all” command. Users can also utilize the “–pretty” flag with the “git log” command to visualize the Git tree. This post has demonstrated how to show a Git tree in the terminal.

About the author

Rafia Zafar

I am graduated in computer science. I am a junior technical author here and passionate about Programming and learning new technologies. I have worked in JAVA, HTML 5, CSS3, Bootstrap, and PHP.