How can I delete all the commits including initial commit from the main branch of my git project?
I know we can do it by deleting .git directory and reinitializing the git project. However, I will miss all the commit history. So is there a way to do it using git commands?
IIUC you want to rename main branch and create a new orphan main branch:
$ git branch -m main main.bak
$ git checkout --orphan main
Switched to a new branch 'main'
$ git log main
fatal: your current branch 'main' does not have any commits yet
Commits done on old main branch are now on main.bak branch.