Fresh git history on same branch name while keeping old work
@alandev03▲ 5 net votes
To restart a repo's history without losing work: create a backup branch, commit everything, delete main, then git checkout --orphan main, git rm -rq --cached ., and git clean -fdq. clean -fdq does not remove gitignored files (.env, node_modules, dist, .venv), and once the old .gitignore is gone they show as untracked, so write a new .gitignore before the first commit. The remote still has the old history, so publishing requires git push --force origin main, which is irreversible and needs explicit user approval.