git-branch-tree
Shows the parent-child relationships between git branches as a printed tree.
Branches that share commit history are nested under their common ancestor;
branches with no identifiable parent appear at the root.
Disclaimer: This is a personal project. The views, code, and opinions expressed here are my own and do not represent those of my current or past employers.
Installation
go install github.com/glennhartmann/git-branch-tree@latest
Or build from source:
git clone https://github.com/glennhartmann/git-branch-tree
cd git-branch-tree
go build -o git-branch-tree .
Quick start
Run inside any git repository:
$ git-branch-tree
The current branch is highlighted in green. Example output:
├─ main
│ ├─ feature
│ │ └─ fix
│ └─ release
└─ hotfix
Modes
Two modes control how the tree is built, selected with -m:
history (default) — infers parent-child relationships from commit history.
A branch is a child of the branch whose tip commit appears in its history at the
point the two histories diverge. Works with no upstream configuration.
upstream — uses the tracking upstream set on each branch
(git branch --set-upstream-to). More explicit and predictable when upstreams
are configured.
$ git-branch-tree -m upstream
├─ origin/main
│ ├─ origin/feature
│ │ └─ feature
│ │ └─ fix
│ └─ origin/release
│ └─ release
└─ origin/hotfix
└─ hotfix
Node collapsing
When two or more branches point to the same commit, --collapse-nodes (on by
default) merges them into a single node. Their names are joined by
--branch-separator (default :).
$ git-branch-tree $ git-branch-tree -c=false
├─ main ├─ main
│ └─ feature:release │ ├─ feature
└─ hotfix │ └─ release
└─ hotfix
Highlighting
The current branch is coloured green by default (-b).
Use -o to colour additional branches blue; the flag is repeatable.
$ git-branch-tree -o feature -o hotfix
Note: the tree-drawer renderer does not support colour.
Flags
| Flag |
Short |
Default |
Description |
--mode |
-m |
history |
Tree-building mode: history or upstream |
--renderer |
-r |
ppds-horizontal-newline |
Output renderer (see below) |
--all |
-a |
false |
Include remote-tracking branches |
--collapse-nodes |
-c |
true |
Merge branches at the same commit into one node |
--branch-separator |
-s |
: |
Separator between collapsed branch names |
--highlight-current-branch |
-b |
true |
Colour the current branch green |
--highlight-other-branch |
-o |
— |
Colour a branch blue; repeatable |
--full-refs |
-f |
false |
Use full refs (refs/heads/…) instead of short names |
--verbose |
-v |
false |
Dump internal data structures (for debugging) |
Renderers
Six renderers are available via -r:
ppds-horizontal-newline (default)
├─ main
│ ├─ feature
│ │ └─ fix
│ └─ release
└─ hotfix
ppds-horizontal
┬─ main ─┬─ feature ── fix
│ └─ release
└─ hotfix
ppds-vertical
├──────────────────┐
main hotfix
├──────────┐
feature release
│
fix
tree-print
├── main
│ ├── feature
│ │ └── fix
│ └── release
└── hotfix
go-tree
└── main
│ ├── feature
│ │ └── fix
│ └── release
└── hotfix
tree-drawer (no colour support)
╭─╮
│ │
╰┬╯
╭──────────┴──╮
╭───┴──╮ ╭──┴────╮
│ main │ │hotfix │
╰───┬──╯ ╰───────╯
╭────┴────╮
╭────┴───╮ ╭──┴────╮
│feature │ │release│
╰────┬───╯ ╰───────╯
│
╭────┴──╮
│ fix │
╰───────╯