Caio Cunha
Caio Cunha

Reputation: 23394

Rebase and changing branch is including all merged commits in pull request

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

Answers (1)

Guillaume Darmont
Guillaume Darmont

Reputation: 5018

Let's have these conventions :

  • upstream is the remote name of the forked project
  • origin is the remote name of your github fork

Here's the correct worflow to update a feature branch with new commits from upstream/master :

  • git checkout my-branch // Switch onto your feature branch
  • git fetch --all // Fetch new commits from all your declared remotes
  • git rebase upstream/master // Rebase your feature branch onto the last commit of upstream/master
  • git 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

Related Questions