Skip to content

Instantly share code, notes, and snippets.

@pyqlsa
Last active January 22, 2023 08:44
Show Gist options
  • Save pyqlsa/b6b5da23a8197c5b139a0ff4bee2e719 to your computer and use it in GitHub Desktop.
Save pyqlsa/b6b5da23a8197c5b139a0ff4bee2e719 to your computer and use it in GitHub Desktop.
git squash commits on main branch
# this should get everything down to a single commit
#
git checkout --orphan tmp-main
git commit -m "initial commit"
# move the local branch
git branch -f main
git checkout main
# delete the temp branch
git branch -d tmp-main
# git push --force
# this one leaves the initial commit in place, but squashes everything else
git reset --soft $(git rev-list --max-parents=0 HEAD)
git commit -m "initial release"
# git push --force
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment