Deciphering “git show-branch” To See Branches And Their Commits

Commands discussed in this section:

  • git show-branch

git show-branch

Let’s start with the repository we created in the Creating And Playing With Branches page.

The Master branch:

  • Commit C1: Created the file README with the contents: This is the README file.
  • Commit C2: Added one more line to the README file: One more line.
  • Commit C3: Created the file Makefile with the contents: #Beginnings of a Makefile

The test branch started with the master branch commit C2:

  • Commit T1 created the file Makefile with the contents: My system test

The below diagram shows the 2 branches and what occurred during each commit:


The git show-branch command shows the branches and the commit history:

$ git show-branch
* [master] Added a Makefile
 ! [test] Add plan file
*  [master] Added a Makefile
 + [test] Add plan file
*+ [master^] Added a second line.

A bit cryptic?

Let’s break it down, starting with the first two lines, until the ““.

In no particular order, each line lists one branch and its most recent commit text in the following format:

  • A “*” begins the line if this branch is the current branch.
  • A “!” begins the line if this branch is not the current branch.
  • The branch name is reported, in [brackets].
  • The branch’s most recent commit is shown.

For example:

show branch above

Below the “” line is the commit history. Every commit on every branch must have a common ancestor at some point. In our example repository: Commit C3 and commit T1 have a common ancestor: C2. The common ancestor of two branches is where the “branch” occurred. Commits before the common ancestor are the same for both branches.

git show-branch shows commits from all branches, until the point where the branches have a common ancestor.

show branch below

Next: Temporarily Stashing Your Work
Previous: Visualizing Branches and Their Commits