Skip to content

Instantly share code, notes, and snippets.

@kennethgeerts
Last active June 30, 2016 09:58
Show Gist options
  • Save kennethgeerts/f15f8ad55e0b0564e18941bd0f070b3e to your computer and use it in GitHub Desktop.
Save kennethgeerts/f15f8ad55e0b0564e18941bd0f070b3e to your computer and use it in GitHub Desktop.

Squashing commits on a feature branch

Suppose you did 3 commits on a feature branch called feature:

ae1a4a5 Foo
a5827db Bar
62d4c80 Baz

Make sure develop branch is up to date:

git checkout develop
git pull --rebase origin develop

Carry out the interactive rebase:

git checkout feature
git rebase -i develop

Now at this point you should see something like the following in your terminal:

pick ae1a4a5 Foo
pick a5827db Bar
pick 62d4c80 Baz

You can now modify your git history. Squash all the commits down into a single commit:

reword ae1a4a5 Foo
fixup a5827db Bar
fixup 62d4c80 Baz

Note: don't use squash as that automatically uses the existing commit message from the commit we're squashing other commits into. Use reword and fixup instead.

Rewrite your feature branch on origin:

git push --force-with-lease origin feature
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment