I disagree.  The correct thing to do is compare the commit graphs in left-right mode.  This isn't directly supported in JGit with a thing called "left-right mode", you have to do configure it yourself in the application level.

Create two RevFlag instances from a RevWalk, call them LOCAL and REMOTE.

parseCommit() the current branch, and add the LOCAL flag to it.  markStart() that commit.

parseCommit() the matching remote branch, and add the REMOTE flag to it.  markStart() that commit.

Step the RevWalk until you get back a commit that contains both LOCAL and REMOTE on it.  That is your common merge base.  But more importantly, as you stepped it looking for this point you built up a list of commits.  If you store those commits into two lists based on which flags they have (only LOCAL ones go into the "outgoing list" and only REMOTE ones go into the "incoming list"), you get a very accurate representation of what is about to sync.

As for finding the matching remote branch, that typically comes from the repository configuration.  Get the Config, find the variables branch.${currentBranchName}.remote and branch.${currentBranchName}.merge.  The first tells you which remote configuration block you need to examine.  The second tells you the branch name in that remote.  You'll then need to examine the remote.${remoteName}.fetch RefSpecs to find the one that matches the branch.merge value, so you can map that to the local reference name.  That local reference name is what you need to resolve in order to parse that remote branch's commit.