Skip to content

Instantly share code, notes, and snippets.

@gep13
Created April 26, 2013 22:12
Show Gist options
  • Save gep13/5470800 to your computer and use it in GitHub Desktop.
Save gep13/5470800 to your computer and use it in GitHub Desktop.
A set of steps which can be used to update a pull request based on changes to upstream master branch and to reduce number of commits to a single one.
# The following assuming that you have both an "origin" and an "upstream" remote created
# If you don't then you will need to configure this. You can verify what the current state is using
# git remote -v
# Which should look something like the following
# origin git@github.com:rismoney/chocolatey.git (fetch)
# origin git@github.com:rismoney/chocolatey.git (push)
# upstream git@github.com:chocolatey/chocolatey.git (fetch)
# upstream git@github.com:chocolatey/chocolatey.git (push)
# If you don't have this, go ahead and add a new remote using what is detailed here
# https://help.github.com/articles/adding-a-remote
# Switch to your master branch
git checkout master
# Grab the latest code from the upstream repo (in my case, this was a "fast forward", not merge conflicts
git fetch upstream
# rebase the branch based on the upstream master
git rebase upstream/master
# Switch to the Issue branch
git checkout Issue-235
# Grab the latest code from the upstream repo (in my case, this was a "fast forward", not merge conflicts
git fetch upstream
# rebase the branch based on the upstream master - this puts your changes on top of the current HEAD
git rebase upstream/master
# Use the -i flag, to do an interactive rebase, which should open your default text editor, in my case notepad
git rebase -i upstream/master
# You should see a list of all your commits, with the word pick in front.
# Starting with the second commit change the first word from pick to fixup
# Repeat for all subsequent comits
# close editor with save
# Now lets rewrite history
# The following command will again open up your default text editor, with the previous commit message.
# This is an oppurtunity to change it to include the commit messages for the other commits,
# which are now part of a single commit
git commit --amend
# Push your changes up to the repo
git push -f origin
#Sit back and admire your work
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment