Go back to the main page

Squashing a pull request

 

I was asked to squash all of the commits of a recent pull request (PR).

  1. The branch I sent in a PR for is called pre-processing.
  2. $ git branch -a
      master
    * pre-processing
      remotes/origin/HEAD -> origin/master
      remotes/origin/master
      remotes/origin/pre-processing
    
  3. Make sure to grab any new commits to the repository you are sending in the PR to.
  4. $ git remote add upstream git@github.com:yeoman/generator-chrome-extension.git
    $ git fetch upstream master
    
  5. Interactive rebase.
  6. $ git rebase -i upstream/master # or just 'git rebase -i master'
    
  7. Change 'pick' to 'squash' for all commits except the first.
  8. This screen will popup within your editor. Notice that there are 6 commits I need to squash into one. All of them are pre-pended with 'pick'.
    Leave the first commit still labelled as 'pick' but change the rest to 'squash'.
  9. Save and exit out of your editor.
  10. Next, git will prompt you for a commit message.
  11. This will be, again, inside of your editor.
    Delete all of the generated individual commit messages and summarize your pull request e.g. Add support for 'grunt watch'.
  12. Save and exit editor.
  13. Force a git push.
  14. $ git push origin pre-processing -f
    
  15. Done. Your PR has been squashed to a single commit.
  • Pushed on 01/08/2014 by Christian