Comment

Jakub Narębski

First, `git log --merges --first-parent` (where `--merges` is a shortcut for `--min-parents=2`) shows all merges into your current branch. If you are interested in programmatic manipulation, use `--format=%H` to output only commit identifiers, and `-1` to show only first merge. You can then combine extracted commit identifier with `^2` suffix, which extract second parent from a commit. You can try to use `git checkout $(git log --merges --first-parent -1)^2`...

Second, after merging a branch (be it `main`, `master`, `origin` aka `origin/HEAD`, or `origin/master`) into your current branch, the state of that branch before the merge becomes current common ancestor of current branch and merged branch. You can find it with `git merge-base HEAD origin` (or whatever two branches you are interested in).