Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save ProgrammerNomad/8e64311743114f2aaa2f8a976115f268 to your computer and use it in GitHub Desktop.

Select an option

Save ProgrammerNomad/8e64311743114f2aaa2f8a976115f268 to your computer and use it in GitHub Desktop.
How to delete github all commit history from main branch
# 1. Create New Empty Branch
git checkout --orphan new_main
# 2. Stage All Files
git add .
# 3. Create Initial Commit
git commit -m "Initial commit"
# 4. Remove Old Main Branch
git branch -D main
# 5. Rename New Branch
git branch -m main
# 6. Force Push
git push -f origin main
⚠️ Important Notes
Force Push Warning: Using -f overwrites remote history permanently
Team Impact: Other developers will need to reset their local repos
Alternative: For selective history cleanup, consider git rebase -i
For Team Members
# Reset local repository after history change
git fetch origin
git reset --hard origin/main
git clean -fd
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment