Reputation: 23394
I'm coming from a SVN background. I've forked and branched a git repository. Then I changed the branch (let's call it my-branch
), committed, pushed and sent a Pull Request.
It happens that the upstream repository has been changed and my PR became invalid due to conflicts generated by the master changes.
How should I proceed to rebase my branch to solve the conflicts and update the PR?
I tried fetching changes from upstream master to local master then rebasing my branch to local master:
git checkout master
git fetch upstream
git merge upstream/master
git push origin master
git checkout my-branch
git rebase master
The problem is that when I resolved the conflicts and committed/pushed the changes, all commits from upstream are also being included in the PR, as if I have made these changes. So, again, how should I proceed to really "rebase" my branch and PR, so I can safely change and commit to the PR only the files I've changed?
Upvotes: 1
Views: 196
Reputation: 5018
Let's have these conventions :
upstream
is the remote name of the forked projectorigin
is the remote name of your github forkHere's the correct worflow to update a feature branch with new commits from upstream/master
:
git checkout my-branch
// Switch onto your feature branchgit fetch --all
// Fetch new commits from all your declared remotesgit rebase upstream/master
// Rebase your feature branch onto the last commit of upstream/mastergit push -f origin my-branch
// Overwrite your remote my-branch
(mandatory since a rebase rewrites commits)Your PR should be updated with the new commits of my-branch
Upvotes: 2