LinuxCommandLibrary

git-show-branch

Visualize branch relationships and commit history

TLDR

Show a summary of the latest commit on a branch

$ git show-branch [branch_name|ref|commit]
copy

Compare commits in the history of multiple commits or branches
$ git show-branch [branch_name1|ref1|commit1 branch_name2|ref2|commit2 ...]
copy

Compare all remote tracking branches
$ git show-branch [[-r|--remotes]]
copy

Compare both local and remote tracking branches
$ git show-branch [[-a|--all]]
copy

List the latest commits in all branches
$ git show-branch [[-a|--all]] --list
copy

Compare a given branch with the current branch
$ git show-branch --current [commit|branch_name|ref]
copy

Display the commit name instead of the relative name
$ git show-branch --sha1-name --current [current|branch_name|ref]
copy

Keep going a given number of commits past the common ancestor
$ git show-branch --more [5] [branch_name1|ref1|commit1 branch_name2|ref2|commit2 ...]
copy

SYNOPSIS

git show-branch [--topic] [--independent] [--date-order] [--list] [--merge-base] [--stdin | <rev>...]

PARAMETERS

-r, --rev-output-reverse
    Show commits in reverse order of output.

-g, --more
    Show more commits than the default limit (usually 20). Can be specified multiple times.

-a, --all
    Show all refs, not just heads.

-c, --color
    Show colored output (default is to use color when outputting to a TTY).

--no-color
    Turn off colored output, even if default is color.

-i, --independent
    Show only branches that are not merged into any other specified branches.

-t, --topic
    Show only topic branches (those not merged into any other specified branch).

-s, --sparse
    Show a more concise output, omitting commit messages and focusing on ancestry.

-m, --merge-base
    Find and show the common merge base of the specified revisions.

--list
    List the branches that contain current HEAD, or the given revision if specified. Does not show history.

--stdin
    Read revisions from standard input, one per line.

--date-order
    Sort commits by commit date. Default is topological order.

--topo-order
    Sort commits by topological order (parent before child). This is the default.

--no-name
    Do not show branch names in the output.

--sha1-name
    Show SHA1 of the branch head instead of the name.

--current
    Mark the current branch (HEAD) specially in the output.

--reflog
    Include reflog entries in the displayed revisions.

<rev>...
    Specify one or more revisions (e.g., branch names, commit SHAs) to display. If none are specified, all local heads are shown.

DESCRIPTION

The git-show-branch command is a powerful tool for visualizing the commit ancestry of multiple branches, making it easier to understand how they diverge and merge. It displays a summary of the commits on the named branches that are not found on the default branch (or common ancestor).

Instead of showing a linear log, git-show-branch provides a columnar output, where each column represents a specified branch. Commits are marked with symbols to indicate their presence and relationship:
! indicates the tip of a topic branch.
* indicates a common commit reachable from multiple branches.
+ indicates a commit unique to a specific branch.
(space) indicates the commit is not present or not unique to that column.

It's particularly useful for reviewing proposed merges, identifying commits unique to a feature branch before integration, or understanding complex repository histories with many active branches.

CAVEATS

The output of git-show-branch can become dense and difficult to read when dealing with a very large number of branches or a deep commit history. Its primary strength lies in visualizing divergence from a common ancestor, rather than a full chronological log of all commits. For detailed commit information, git log is more appropriate.

OUTPUT FORMAT

The output uses a specific format to convey information:
Each column represents a specified branch.
An ! in a column indicates the tip of that branch.
A * indicates a common commit reachable from multiple specified branches.
A + indicates a commit unique to the branch represented by that column.
A blank space indicates the commit is not reachable from that branch or is not unique to it.
The commit subject line is preceded by the names of the branches whose tips are ancestors of the commit and, if applicable, the commit SHA-1 (if --sha1-name is used) and a short summary of the commit message.

EXAMPLES

git show-branch master develop feature/x
Shows the commits on 'master', 'develop', and 'feature/x' branches, highlighting their common history and unique commits.

git show-branch --merge-base HEAD origin/master
Displays the common merge base commit between the current HEAD and 'origin/master'.

git show-branch --list
Lists all branches that contain the current HEAD commit.

HISTORY

The git-show-branch command has been a fundamental part of Git since its early days, addressing the crucial need for developers to visually understand the relationships and divergence points between different lines of development. Its design emphasizes a clear, column-based representation of commit ancestry, making it an invaluable tool for complex branching workflows, even as other visualization tools have emerged.

SEE ALSO

git log(1), git branch(1), git merge-base(1), git diff(1)

Copied to clipboard