Find the last local git commit that is also present in/was pushed to upstream

Viewed 37

Is there a way to get the last local Git commit that I also pushed on upstream?

To explain a little more: I would like the last local commit that was also pushed on upstream, not to be confused by the last upstream commit which is not always also local(because you can bring upstream commits using git fetch and the fetched commits are not local anymore).

I understand that one could make an algorithm that looks over the upstream commits and over the local commits, does some comparisons and determine which was the last local commit i.e. that appears when git loging and is also present in upstream but a git command that gives this information would be very handy.

1 Answers

Most of the time that would be

git merge-base origin/master master

(substituting whatever branch name for master).

The major exception would be if either the local or remote branch has been rewritten, so that they don't have any common commits. (Well... they'd still have common history probably, but nothing you'd think of as "part of' the branch.) In that case, there's not a good answer other than to eyeball it.

Related