How to Remove All Commits From a Branch


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
Second Head Post
This is a post from Second Head. So please, don’t expect too much.

Related Content