Pretty Git Branch Graphs
To create pretty Git branch graphs, you can use several tools and commands that visualize the commit history and branch structure in an easy-to-understand format. Here are some popular methods:
Method 1: Using git log
with Graph Options
Git provides built-in options to visualize the commit history in a graph format.
Simple Graph View:
git log --graph --oneline
This command shows a simple, one-line-per-commit graph.
Detailed Graph View:
git log --graph --oneline --decorate --all
This command adds decoration (branch names and tags) and shows commits from all branches.
Customizing the Log Output:
git log --graph --pretty=format:'%C(auto)%h%d %s %C(blue)<%an>' --all
This command customizes the log format to show the commit hash, decorations, commit message, and author name.
Method 2: Using gitk
gitk
is a graphical history viewer for Git repositories.
Open
gitk
: This command opens a graphical window showing the commit history and branch structure.gitk --all
Method 3: Using Third-Party Tools
Several third-party tools provide more advanced and visually appealing Git graphs.
- GitKraken:
- GitKraken is a popular Git GUI client with a visually appealing and user-friendly interface
- SourceTree:
- SourceTree is another popular Git GUI client that offers detailed branch graphs
- Git Graph Extension for VS Code:
- If you use Visual Studio Code, the Git Graph extension provides an interactive graph of your repository
Example: Using git log
for a Pretty Graph
Here is an example command that provides a comprehensive and visually appealing branch graph:
git log --graph --abbrev-commit --decorate --all --format=format:'%C(bold blue)%h%C(reset) - %C(dim white)%an%C(reset) %C(bold yellow)%d%C(reset)%n''%C(white)%s%C(reset)' --date=short
This command does the following:
-graph
: Draws a text-based graph of the commit history.-abbrev-commit
: Shows only the abbreviated SHA-1.-decorate
: Adds decorations to the commit entries.-all
: Shows all branches.-format
: Customizes the format of the log output, with colors for better readability.-date=short
: Displays the date in a short format.
Example Output
When you run the above command, you get an output like this:
* b6b8a1d - AuthorName (HEAD -> main, origin/main)
| Add new feature
* c3d9f0e - AuthorName (feature-branch)
| Work on feature
| * e9a3f7b - AuthorName (bugfix-branch)
|/ Fix bug
* 12d4a5c - AuthorName
Initial commit
Summary
- Built-in Git Options: Use
git log
with-graph
and other formatting options for a simple yet powerful graph view. - Graphical Tools: Use tools like
gitk
, GitKraken, SourceTree, or the Git Graph extension for VS Code for more advanced graphical views.
By leveraging these methods, you can easily create and view pretty Git branch graphs to understand your repository's commit history and branch structure.
Make your mark
Join the writer's program
Are you a developer and love writing and sharing your knowledge with the world? Join our guest writing program and get paid for writing amazing technical guides. We'll get them to the right readers that will appreciate them.
Write for usBuild on top of Better Stack
Write a script, app or project on top of Better Stack and share it with the world. Make a public repository and share it with us at our email.
community@betterstack.comor submit a pull request and help us build better products for everyone.
See the full list of amazing projects on github