skip to content
back to til

Squashing Commits with Merge Commits

til

Squashing combines several Git commits into one. Rebasing a branch without merge commits is straightforward, but merge commits make it trickier. Use a temporary branch to create the combined commit, then move the feature branch to it:

git checkout -b temp {main-branch}
git merge --squash {feature-branch}
git commit
git checkout {feature-branch}
git reset --hard temp
git branch -D temp
git push -u origin {feature-branch} --force

This combines the commits in feature-branch into one and force-pushes the rewritten branch to the remote repository.

comments