This page looks best with JavaScript enabled

How to Clear All Commit History from a Git Repository

 ·  ☕ 1 min read

Here we take clearing the entire commit history of the main branch as the example.

  1. Switch to the main branch
1
git checkout main
  1. Create a clean branch
1
git checkout --orphan new_main
  1. Commit all files
1
2
git add -A
git commit -m "msg"
  1. Delete the main branch
1
git branch -D main
  1. Rename the new branch to main
1
git branch -m main
  1. Force push to the remote repository
1
git push -f origin main

WeChat Official Account
WRITTEN BY
WeChat Official Account