Skip to content

Instantly share code, notes, and snippets.

@obar1
Created November 3, 2025 10:20
Show Gist options
  • Select an option

  • Save obar1/13e6adccea3015baaa0761b3c70f946d to your computer and use it in GitHub Desktop.

Select an option

Save obar1/13e6adccea3015baaa0761b3c70f946d to your computer and use it in GitHub Desktop.
rewrite git history when not important

Step 1: Checkout the branch you want to squash (e.g., main)

git checkout main

Step 2: Rebase interactively from the root commit

git rebase -i --root

This opens an editor showing all commits. Change pick to squash (or s) for all commits except the first one. Save and close the editor, then write a new commit message.

Step 3: Force push the rewritten history to the remote

git push origin main --force-with-lease
@obar1
Copy link
Author

obar1 commented Nov 11, 2025

likely you need then


git fetch origin
git reset --hard origin/main

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment