I would expect the simpler invocation below to do what you need.
git rebase -i $(git merge-base HEAD master)
The documentation for git merge-base --fork-point
shows that the option can highly useful but in the context of a complicated history. Your question does not indicate that you have been doing a lot of history rewriting, so --fork-point
may be overkill for your case.
Discussion on fork-point mode
After working on the topic branch created with
git switch -c topic origin/master
the history of remote-tracking branch origin/master
may have been rewound and rebuilt, leading to a history of this shape:
o---B2
/
---o---o---B1--o---o---o---B (origin/master)
\
B0
\
D0---D1---D (topic)
where origin/master
used to point at commits B0, B1, B2 and
now it points at B, and your topic branch was started on top of it
back when origin/master
was at B0, and you built three commits,
D0, D1, and D, on top of it. Imagine that you now want to rebase the work you did on the topic on top of the updated origin/master
.
In such a case, git merge-base origin/master topic
would return the
parent of B0 in the above picture, but B0^..D
is not the range of
commits you would want to replay on top of B (it includes B0,
which is not what you wrote; it is a commit the other side discarded
when it moved its tip from B0 to B1).
git merge-base --fork-point origin/master topic
is designed to help in such a case. It takes not only B but also B0, B1, and B2 (i.e. old tips of the remote-tracking branches your repository’s reflog knows about) into account to see on which commit your topic branch was built and finds B0, allowing you to replay only the commits on your topic, excluding the commits the other side later discarded.
The git rebase --fork-point
documentation makes the connection between git rebase --fork-point
and git merge-base --fork-point
.
When --fork-point
is active, forkpoint will be used instead of
upstream to calculate the set of commits to rebase, where forkpoint is the result of
git merge-base --fork-point <upstream> <branch>
command. (See git-merge-base
.) …