How to Visualize Git Repository

John Wachira Feb 02, 2024
How to Visualize Git Repository

In this article, we will see how you can get a visual of your repository. We will use the git log command to see the topography of our repository.

Visualize Git Repository

Most developers using Git spend most of their time on the bash terminal. An easy git log command will list all your commits.

However, it will be hard to develop a mental model of your repository. Another person may find it difficult to understand your workflow.

Luckily, you can use methods to visualize your repository, which we will cover shortly.

In the example below, we use the git log --oneline --all to see the history of our repository.

pc@JOHN MINGW64 ~/Git (main)
$ git log --oneline --all
e923721 (refs/stash) WIP on main: 78129a6 Revert "$git status"
032ee0a index on main: 78129a6 Revert "git status"
78129a6 (HEAD -> main, New_Branch, Last_Branch, Branch1) Revert "$git status"
195e5c3 git status
7b19db4 first commit
b2f7710 (origin/main) Initial commit

The above is only a simple flattened view. You can add the --graph argument to get a better view.

Your command should then read git log --oneline --all --graph.

Example:

pc@JOHN MINGW64 ~/Git (main)
$ git log --oneline --all --graph
*   e923721 (refs/stash) WIP on main: 78129a6 Revert "git status"
|\
| * 032ee0a index on main: 78129a6 Revert "git status"
|/
* 78129a6 (HEAD -> main, New_Branch, Last_Branch, Branch1) Revert "git status"
* 195e5c3 $git status
* 7b19db4 first commit
* b2f7710 (origin/main) Initial commit

That looks better, but we can identify branches and tag labels further.

We use the --decorate argument in the following context.

git log --oneline --all --graph --decorate

You can also add the --color argument to make the layout better in the following context.

git log --oneline --all --graph --decorate --color

It is a rather long command to type whenever you want to visualize your repository. Make it easier for yourself by assigning an alias to your command, as shown below.

In the example below, we will give the git log --oneline --all --graph --decorate --color command the alias glt.

pc@JOHN MINGW64 ~/Git (main)
$ alias glt='git log --oneline --decorate --graph --all'

Let us run the command using our alias.

pc@JOHN MINGW64 ~/Git (main)
$ alias glt
alias glt='git log --oneline --decorate --graph --all'

pc@JOHN MINGW64 ~/Git (main)
$ glt
*   e923721 (refs/stash) WIP on main: 78129a6 Revert "$git status"
|\
| * 032ee0a index on main: 78129a6 Revert "$git status"
|/
* 78129a6 (HEAD -> main, New_Branch, Last_Branch, Branch1) Revert "$git status"
* 195e5c3 $git status
* 7b19db4 first commit
* b2f7710 (origin/main) Initial commit
Author: John Wachira
John Wachira avatar John Wachira avatar

John is a Git and PowerShell geek. He uses his expertise in the version control system to help businesses manage their source code. According to him, Shell scripting is the number one choice for automating the management of systems.

LinkedIn

Related Article - Git Log