Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
How to squash commits on git branch

How to squash commits on git branch

When submitting a pull request, it's important that you squash your commits to keep our repository concise and clean.

You will need to use VIM to do this.

Make sure your branch is up to date with the master branch.

  • Run git rebase -i master.
  • VIM will be opened
  • You should see a list of commits, each commit starting with the word "pick".
  • Press i or s on the console -- This will bring you to insert/edit mode of VIM
  • Make sure the first commit says "pick" and change the rest from "pick" to "squash". -- This will squash each commit into the previous commit, which will continue until every commit is squashed into the first commit.
  • Save and close the editor by pressing Esc and type :wq.
  • It will give you the opportunity to change the commit message.
  • Press i or s to edit
  • Non-commented lines will appear as commit messages. Commented lines (preceded with #) will not appear on the commit message.
  • Save and close the editor again by pressing Esc and type :wq.
  • Then you have to force push the final, squashed commit: git push -f.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment