How to Clear All Git Commit History

Use git checkout –orphan new_branch to create an independent branch new_branch based on the current branch;

Terminal window
git checkout --orphan main

Add all file changes to the scratch space

Terminal window
git add -A

Submit and add submission record

Terminal window
git commit -am "init"

Delete the branch you want to remove the commit record. This is master.

Terminal window
git branch -D master

Rename the current independent branch to master

Terminal window
git branch -m master

Force push to remote branch

Terminal window
git push -f origin master

If git push -f reports an error when pushing, it means that the permissions are insufficient. Or the main branch of Gitlab will be protected by default. You need to go to Project => Settings => Warehouse => Protected Branch to unprotect it.