Forrest logo
back to the git tool

git-merge-base:tldr:0a2eb

git-merge-base: Print the best common ancestor of two commits.
$ git merge-base ${commit_1} ${commit_2}
try on your machine

The git merge-base command is used in Git to find the common ancestor of two git branch heads or commits.

In the given command, ${commit_1} and ${commit_2} are placeholder variables representing the two commits or branch heads whose common ancestor you want to find.

When you run the command git merge-base ${commit_1} ${commit_2}, Git identifies the common ancestor commit (if any) between the two specified commits.

The output of this command will be the commit hash of the common ancestor. If there is no common ancestor between the specified commits, it will simply return an empty output.

This command is often used in scenarios where you want to find the point at which two branches diverged from each other, or to determine the base commit for a feature branch that you want to merge back into the main branch.

This explanation was created by an AI. In most cases those are correct. But please always be careful and never run a command you are not sure if it is safe.
back to the git tool