How is a merge-base done in JGit?


I’m looking at the JGit Documentation, currently at version, and I cannot find the equivalent of git-merge-base.

I would like to determine if a branch is up-to-date, behind, ahead, or diverged, as shown in git: check if pull needed.

What is the most concise way in JGit to find as good common ancestors as possible for a merge?


You can use RevFilter.MERGE_BASE for that:

RevWalk walk = new RevWalk(repository);
RevCommit mergeBase =;

Also note that there is BranchTrackingStatus if all you are interested in is ahead/behind count of a branch compared to its remote-tracking branch.

Answered By – robinst

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published