How to Remove All Commits From a Branch
Contents
At times it’s necessary to remove all commits from a branch. This can be useful when you want to start fresh or when you want to remove all history from a branch.
Here’s how you can remove all commits from a main
branch:
git checkout main
git checkout --orphan temp-branch
git add -A
git commit -m "Initial commit"
git branch -D main
git branch -m main
git push origin main --force
Links:
- How do I create a master branch in a bare Git repository?
- how to delete all commit history in github?
Second Head Post
This is a post from Second Head. So please, don’t expect too much.