Simplest thing to do is to rebase your new branch on origin/master
.
You started with this.
A - B - C [master]
[origin/master]
A, B, and C are existing commits. master
is your local branch and origin/master
tracks the last place you saw the upstream master
branch. They both point at commit C.
After you merged your new branch into master
, you had something like this.
1 - 2 - 3 [master]
/
A - B - C [origin/master]
The upstream remains at C, but your local master
is now 3 commits past it. Your local master
is contaminated with local commits.
After you made your second branch off master and committed to it, you had this.
4 - 5- 6 [second]
/
1 - 2 - 3 [master]
/
A - B - C [origin/master]
As you can see, second
also contains 1, 2, and 3 -- your work from the first branch. To fix this, move 4, 5, and 6 to be on top of origin/master
instead.
git rebase --onto origin/master master second
That says to move everything from (but not including) master
to (and including) second
onto origin/master
. That is 4, 5, and 6. The result is this.
1 - 2 - 3 [master]
/
A - B - C [origin/master]
\
4' - 5' - 6' [second]
Note: this assumes 4, 5, and 6 do not rely on 1, 2, and 3. If they do, leave everything as it is and note the dependency in the pull request.
In general, when working with an upstream repository...
- Branch from
origin/master
.
- Do not merge nor commit anything to
master
.
This ensures your pull requests don't get contaminated with local changes or work from other pull requests.