First, you should always make your PR form a branch, not from master
.
master
is for mirroring upstream/master
, with 'upstream
' being the name of the original repository that you forked.
In your case, make sure that:
- make sure that
upstream
exists (git remote -v
),
- make a branch in order to reference your current patches, and
- reset
master
to upstream/master
:
Before:
z--z (upstream/master, with new commits)
/
z--y--y--y (master with local patches, origin/master)
Memorize current work:
git checkout master
git checkout -b mybranch
# Or, With git 2.23+
git switch -c myBranch master
# if remote "upstream" does not yet exist
git remote add upstream /url/original/repo
git fetch upstream
# reset master to upstream/master
git checkout master
git reset --hard upstream/master
git push --force
y--y--y (mybranch)
/
z--z--z (master, upstream/master, origin/master)
# replay the patches (even they are rejected for now) on top of master
git switch mybranch
git rebase master
git push -u origin mybranch
y'--y'--y' (mybranch, origin/mybranch)
/
z--z--z (master, upstream/master, origin/master)
Here: git reset --hard upstream/master
will reset master
HEAD on the updated upstream/master
, in order for master to reflect the exact same history as the one in the original repository.
But since some commits where previously done on master
and pushed on the fork (origin/master
), you would need to replace that history with the new master
state. Hence the git push --force
.
Rebasing mybranch
allows for those current patches to be based on the most up-to-date commit of the original repository.