TLDR; use git show-tree
, or the git lg
alias (my preferred choice).
1. To show all branches (including remote branches) in a tree view:
Use git show-tree
:
Note: git show-tree
is not part of core git
. You have to install it as an extra utility, known as "git-extras". On Linux Ubuntu, I do that with sudo apt install git-extras
. Find your operating system in the installation instructions here and follow the instructions to install it: Installing git-extras.
Tested on Ubuntu:
# Install it
sudo apt install git-extras
# Run it:
git-show-tree
# OR (same thing)
git show-tree
This produces an effect similar to the 2 most upvoted answers here.
Source: http://manpages.ubuntu.com/manpages/bionic/man1/git-show-tree.1.html
Examples:
man git show-tree
shows the following example:
EXAMPLES
Output the commit history log for all branches as tree view:
* 4b57684 (HEAD, develop) Merge branch upstream master.
|\
| * 515e94a Merge pull request #128 from nickl-/git-extras-html-hyperlinks
| |\
| | * 815db8b (nickl/git-extras-html-hyperlinks, git-extras-html-hyperlinks) help ronn make hyperlinks.
| * | 7398d10 (nickl/develop) Fix #127 git-ignore won´t add duplicates.
| |/
| | * ab72c1e (refs/stash) WIP on develop: 5e943f5 Fix #127 git-ignore won´t add duplicates.
| |/
|/|
* | 730ca89 (bolshakov) Rebase bolshakov with master
|/
* 60f8371 (origin/master, origin/HEAD, master) Merge pull request #126 from agrimaldi/fix-changelog-last-tag
* 9627780 (tag: 1.7.0) Release 1.7.0
* 2e53ff6 (tag: 1.6.0) Release 1.6.0
* bbd32d8 (tag: 1.5.1) Release 1.5.1
| * 6b6b758 (nickl/gh-pages, gh-pages) add example git-extras to gh-pages
| * 19cfd11 (origin/gh-pages) Index page
| | * 881a70e (tag: 1.5.0) Release 1.5.0
| |/
|/|
* | 4db5ee0 (tag: 1.4.0) Release 1.4.0
* | 9b0bc89 (tag: 1.3.0) Release 1.3.0
* | be49961 (tag: 1.2.0) Release 1.2.0
* | c1d2dfc (tag: 1.1.0) Release 1.1.0
* | 4a56adb (tag: 1.0.0) Release 1.0.0
* | 948308b (tag: 0.9.0) Release 0.9.0
* | 40b131d (tag: 0.8.1) Release 0.8.1
* | 391431d (tag: 0.8.0) Release 0.8.0
And here is a sample output of git show-tree
on the ardupilot repo:

Also, if you have arcanist installed (correction: Uber's fork of arcanist installed--see the bottom of my answer here for installation instructions), arc flow
shows a beautiful dependency tree of upstream dependencies (ie: which were set previously via arc flow new_branch
or manually via git branch --set-upstream-to=upstream_branch
). Example output of arc flow
:
master
└──graft-D999
└──new_feature_1
└──new_feature_2
I really find the arc flow
view beautiful and useful, so I have this (inactive, and not-yet-functional) git tree
open-source project where I plan to duplicate its behavior: https://github.com/ElectricRCAircraftGuy/git-tree.
2. To show one branch in a "tree-like" fashion:
# Show the currently-checked-out branch
git lg
# OR: show branch_name
git lg branch_name
You can add -p
or --patch
to show the lines changed too:
git lg -p
# OR
git lg --patch
To install the git lg
alias (source: https://coderwall.com/p/euwpig/a-better-git-log):
git config --global alias.lg "log --color --graph \
--pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) \
%C(bold blue)<%an>%Creset' --abbrev-commit"
Example output showing forks and merges and stuff on the sshfs
repo:

Bonus git tricks:
Related:
- What's the difference between `arc graft` and `arc patch`?