Squash commit- A step by step guide

Step 1: Fetch the latest develop

Make sure your local develop branch is up to date:


git fetch origin
git checkout develop
git pull origin develop

Step 2: Switch to your feature branch

git checkout your-feature-branch

Step 3: Start interactive rebase

Run:

git rebase -i origin/develop

This opens an interactive rebase editor showing your commits like this:

pick 123abc Add initial feature
pick 456def fix typo
pick 789ghi try this

Step 4: Squash commits

Leave the first commit as pick.

Change the rest to squash (or s):

pick 123abc Add initial feature
squash 456def fix typo
squash 789ghi try this

Step 5: Edit commit message

Git will prompt you to combine commit messages. Clean it up so it looks like:

Add feature X with proper implementation

Save and exit.

Step 6: Resolve conflicts (if any)

If there are conflicts:


git status
# Fix files
git add <file>
git rebase --continue

Step 7: Push changes

Because history changed, you need a force push:

git push --force

Result

  • Your branch now has one clean commit (or a few meaningful ones).
  • It’s rebased on the latest develop.
  • No messy merge commits.

Leave a comment