Last active
April 9, 2025 10:12
-
-
Save ProgrammerNomad/8e64311743114f2aaa2f8a976115f268 to your computer and use it in GitHub Desktop.
How to delete github all commit history from main branch
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 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