Finding a branch point with Git?
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
Introduction
A branch point (or fork point) is the commit where a branch diverged from its parent branch. Git does not explicitly store this information — branches are just pointers to commits, and any commit can be an ancestor of multiple branches. To find the branch point, you use git merge-base to find the common ancestor between two branches. This is essential for understanding what changed on a branch, preparing for merges, or creating targeted rebases.
Method 1: git merge-base (Most Common)
git merge-base finds the best common ancestor — the most recent commit that is reachable from both branches. This is the branch point.
Method 2: git merge-base --fork-point (Reflog-Aware)
--fork-point consults the reflog to handle cases where main was rebased or force-pushed after the branch was created. It finds the original fork point even if the common ancestor changed.
Method 3: Visual with git log --graph
Method 4: git log with Range
Method 5: git diff from Branch Point
The three-dot ... syntax in git diff automatically uses the merge base, showing only what changed on the right side since divergence.
Method 6: Find Branch Point in a Script
Multiple Merge Bases
When branches have been merged back and forth, there can be multiple common ancestors:
Practical Use Cases
Rebase onto the correct point
Create a patch of all branch changes
Count commits on a branch
Common Pitfalls
- Assuming Git stores the branch point explicitly: Git does not record where a branch was created. It only stores commit parents.
git merge-basecomputes the branch point from the commit graph each time. If the graph is complex (many merges), the result may not match your intuition. - Reflog expiration with
--fork-point:--fork-pointdepends on the reflog, which expires after 90 days by default. On CI servers or fresh clones, the reflog may be empty, causing--fork-pointto return nothing. Use plaingit merge-baseas a fallback. - Shallow clones:
git clone --depth Ncreates a shallow clone with limited history.git merge-basemay fail or return incorrect results because the branch point commit is not in the local repository. Usegit fetch --unshallowto get full history. - Confusing
..and...ingit logvsgit diff: Ingit log,A..Bshows commits in B not in A. Ingit diff,A...Buses the merge base (branch point). The three-dot syntax has different meanings depending on the command. - Multiple merge bases after criss-cross merges: If branches have been merged back and forth,
git merge-basereturns the most recent common ancestor, which might not be the original fork point. Usegit merge-base --allto see all candidates.
Summary
- Use
git merge-base feature mainto find the commit where a branch diverged - Use
--fork-pointfor reflog-aware detection (handles rebased base branches) - Use
git diff main...feature(three dots) to see changes since the branch point - Use
git log main..feature(two dots) to list commits on the feature branch - Git does not store branch points explicitly — they are computed from the commit graph
- Shallow clones and expired reflogs can cause incorrect branch point detection

