Pre-requisite

  • Git is installed locally.

Procedures

  1. Checkout the non-master branch to be squashed.
  2. Ensure that the branch is up to date from the master.
  3. Open a terminal and change the directory to the root of checked out branch.
  4. Run the following command:
    git rebase -i master
  5. Once a text editor opens and leave the first pick alone and the subsequent picks must be replaced with squash. For example:
    From

    pick < hash1 > < message1 >
    pick < hash2 > < message2 >
    pick < hash3 > < message3 > 
    pick < hash4 > < message4 >
    

    To

    pick < hash1 > < message1 >
    squash < hash2 > < message2 >
    squash < hash3 > < message3 > 
    squash < hash4 > < message4 >
    
  6. Save the update and close the editor.
  7. Another editor will open to update the message since git is about the combine multiple commits.
  8. Update the message if necessary.
  9. Save and close the editor.
  10. If everything went fine your branch is now squashed.