How to nuke the history and end up with a single-commit branch still called main.

Preflight

# 0) Be on latest and clean
git fetch origin
git checkout main
git pull
git status  # should say "working tree clean"

# 1) Make a local backup of current main (easy rollback)
git branch backup-main main
# (Optional but safer) make a mirror backup outside the repo:
# git clone --mirror git@github.com:YOU/REPO.git REPO-backup.git

Create a fresh, history-free commit

# 2) Create an orphan branch (no parents / no history)
git checkout --orphan clean-main

# 3) Stage and commit the current snapshot
# git add -A  # ** NOT A GOOD IDEA, OLD STUFF SHOULD ALREADY BE STAGED **
git commit -m "Initial public release"

Replace local main with the clean history

# 4) Remove the old local main (we have backup-main if needed)
git branch -D main

# 5) Rename the clean branch to 'main'
git branch -m clean-main main

Force-push to overwrite remote main

# 6) Push and replace origin/main with your single commit
git push -u origin main --force

Your repo now appears to have started today with one commit, and the branch name remains main.


Optional cleanups / checks (do these right after)

  • Tags: If you’ve ever pushed tags pointing to old commits, consider deleting them so they don’t expose old history:

bash git tag # inspect # delete locally git tag -d TAGNAME # delete on remote git push origin :refs/tags/TAGNAME * Other branches: Delete any other branches (local/remote) that carry old history:

bash git branch # local git branch -D old-branch git push origin --delete old-branch * Secrets: Rotate any credentials that have ever been committed. Assume they’re compromised once the repo goes public. * License & docs: Add LICENSE, README, SECURITY.md, etc. * Make public: On GitHub → Settings → Change visibility → Public.

If you paste your git branch --all output, I can tell you exactly which branches/tags you should delete (if any) before you flip the repo to public.