Notes
Notes

Fresh Branch Without Old History

Start a clean git branch with no commit history from the previous branch.

Author
Peter Shaan
Published
Topics
git
94 views

Sometimes you want a fresh start — same codebase, zero history. This is useful when a branch has too many messy commits and you just want to ship clean.

Create an Orphan Branch

An orphan branch has no parent commits — it starts completely empty.

git checkout --orphan fresh-start

Remove All Tracked Files

git rm -rf .

Stage Everything Fresh

git add .

Make the First Commit

git commit -m "initial commit"

Force Push to Remote

git push origin fresh-start --force

If you want to replace main, switch the default branch in your repo settings first, then delete and re-push.


Alternative: Squash All Commits into One

If you want to keep the same branch name but clean up the history:

git checkout --orphan temp
git rm -rf .
git add .
git commit -m "initial commit"
git branch -D main
git branch -m main
git push origin main --force