Git Reference ยท Branches and Tags
git show-branch command
Reference for git show-branch: read the column chart of commits, use --more, --merge-base, --independent and --list to compare branches and find where they diverged.
git show-branch prints a compact chart of the commits on several branches, one column per branch, so you can see at a glance where they diverge and where they were merged. It is an older, text-only cousin of git log --graph --oneline --all, and its output is easy to parse in scripts.
Without arguments it shows all local branches. The upper part of the output lists the branches with a marker per column; a line of dashes separates it from the commit rows.
git show-branch main feature git show-branch --list git show-branch --merge-base main feature
Try it
Press Run (or Ctrl + Enter) to see the result here.
Program input ยท what you'd type while the program runs
Type the answers before you press Run, one per line. Each time the program reads a line (with read or cat), it gets the next line from this box.
Press Run (or Ctrl + Enter) to see the result here.
Program input ยท what you'd type while the program runs
Type the answers before you press Run, one per line. Each time the program reads a line (with read or cat), it gets the next line from this box.
Syntax
git show-branch [-a | --all] [-r | --remotes] [--topo-order | --date-order] [--current] [--color[=<when>] | --no-color] [--sparse] [--more=<n> | --list | --independent | --merge-base] [--no-name | --sha1-name] [--topics] [(<rev> | <glob>)...] git show-branch (-g | --reflog)[=<n>[,<base>]] [--list] [<ref>]
| Name | Description |
|---|---|
<rev>, <glob> |
Branches (or any revisions) to show; globs like topic/* select several. |
-a, --all |
Show remote-tracking branches too. |
-r, --remotes |
Show only remote-tracking branches. |
--more=<n> |
Show n more commits past the common ancestor. |
--list |
Same as --more=-1: list the branch heads and omit the commit rows. |
--merge-base |
Print the best common ancestors instead of the chart (like git merge-base). |
--independent |
Print only the revisions that are not ancestors of the others. |
--no-name |
Hide the name column in each row. |
--sha1-name |
Use abbreviated object names instead of branch~N names. |
--topics |
Hide commits that are reachable from the first listed branch. |
-g, --reflog |
Show the reflog entries of one ref as columns. |
--current |
Include the current branch even if not listed. |
Returns: the chart on standard output.
Errors: an unknown name fails with "bad sha1 reference".
Usage notes
- Reading the chart. Each branch has a column. In the header,
*marks the current branch and!the others. In the rows, a mark in a column means that commit is reachable from that branch (*in the current branch's column,+in the others), and a-marks a merge commit. The names in brackets, such as[feature^], are revisions you can reuse. - Names like
main^,topic~2in each row give you a revision you can paste into other commands. - It stops at the common ancestor of all branches listed, which makes it ideal for "what is only on my branch" at a glance.
- Limited columns. It handles only a few dozen refs at once (one column each); with more, narrow the list with globs.
- Not for big histories. It walks commits until the ancestor is found, so very divergent histories print long charts; use
git log --oneline --graphfor exploration. - Use
--merge-baseand--independentwhen scripting; they are the straightforward forms ofgit merge-baseand the "heads" computation. git show-branch -gshows reflog entries as a chart, a quick way to review what changed in recentHEADmoves.
Related
git log,git merge-base,git branch,git rev-list,git reflog- Lessons: Branches, Merging