Updating pull request branch with changes from upstream in GitHub

I don’t know if it’s the most efficient way but here’s one way of dealing with updating a pull request from a personal branch after upstream/master has been updated.

I update my origin/master:


git checkout master

git fetch upstream

git merge upstream/master

I switch to my local branch:

git checkout local-branch-name

“Pop” the PR commit back into unstaged:

git reset HEAD^

This will remove the last commit (I usually rebase all my PR commits into one before submitting a PR but you can also specify HEAD~x where x is the number of commits you want to pop back out) and put it back into unstaged.

And then try to merge master into the branch:

git merge master local-branch-name

If it merges cleanly I can proceed with a commit. If it can’t merge cleanly, I stash the unstaged changes, I merge and then pop the stash likewise:

git stash

git merge master local-branch-name

git stash pop

And then take care of the merge conflicts manually. You will get info on which files are in conflict by doing:

git status

After all of this I can commit and push the branch to GitHub which will update the pull request.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s