Before you run the command below, make sure you are in the right branch and have committed and pushed your most recent changes.
First, get the most recent version of master:
git fetch origin
Next, rebase:
git rebase origin/master
There might be some conflicts that you need to resolve before you move on.
git rebase -i HEAD~n
Where n is the number of commits for that branch.
This step is faster to do if you associate a text editor with git: https://help.github.com/articles/associating-text-editors-with-git/
Say you did a total of 3 commits. You're going to see something like this:
pick aaa1111 A first commit
pick bbb2222 A second commit
pick ccc3333 A third commit
You're going to want to substitute all pick
's EXCEPT the one of the first commit with an s
for squash:
pick aaa1111 A first commit
s bbb2222 A second commit
s ccc3333 A third commit
boom! Save and close window (if you're working in a text editor). Next, you're going to see all of your previous commits with their respective messages. Feel free to just delete all of them except the first commit and its message, which you can modify if you want to. Save and close window.
git push origin head -f
You're all set.
Check out autosquash: https://robots.thoughtbot.com/autosquashing-git-commits