Skip to content

Git: Find latest common ancestor of two branches

To find the latest common ancestor of two branches, which is required, for instance, when squashing your commits, instead of scrolling through you git log history you can use the git-merge-base1 tool.

An example is worth a 1000 words


# for instance
git merge-base develop main 
  # will output the hash of the latest commit in common


Make sure that both branches are up to date to avoid the apocalypse!

  1. Official git-merge documentation can be found here: