Skip to content

Instantly share code, notes, and snippets.

@aamishbaloch
Last active September 18, 2017 15:19
Show Gist options
  • Save aamishbaloch/02e46e3b2c8781704c9af8c0123b1796 to your computer and use it in GitHub Desktop.
Save aamishbaloch/02e46e3b2c8781704c9af8c0123b1796 to your computer and use it in GitHub Desktop.
Squash & Merge your Commits for Pull Requests

Squash & Merge your Commits for Pull Requests

The method mentioned below only allows you to squash the last X consecutive commits into a single commit. Also, if you have merged master into your branch along the way, you will have to manually merge your new (squashed) commit into master and resolve the merge conflicts.

Combining the commits (Method 1)

To squash the last 3 commits into one:

git reset --soft HEAD~3
git commit -m "New message for the combined commit"

Combining the commits (Method 2)

To squash the last 3 commits into one:

git rebase -i HEAD~3

You can squash the commits manually from terminal.

Pushing the squashed commit

If the commits have been pushed to the remote:

git push origin +name-of-branch

The plus sign forces the remote branch to accept your rewritten history, otherwise you will end up with divergent branches

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment