- Git is installed locally.
- Checkout the non-master branch to be squashed.
- Ensure that the branch is up to date from the master.
- Open a terminal and change the directory to the root of checked out branch.
- Run the following command:
git rebase -i master
- Once a text editor opens and leave the first pick alone and the subsequent picks must be replaced with squash. For example:
pick < hash1 > < message1 > pick < hash2 > < message2 > pick < hash3 > < message3 > pick < hash4 > < message4 >
pick < hash1 > < message1 > squash < hash2 > < message2 > squash < hash3 > < message3 > squash < hash4 > < message4 >
- Save the update and close the editor.
- Another editor will open to update the message since git is about the combine multiple commits.
- Update the message if necessary.
- Save and close the editor.
- If everything went fine your branch is now squashed.