TianDev

How to delete all commit history in GIT

Posted: September 10, 2020 by anhkevin

If you want to delete all of our commits history, but keep the code in its current state, try this

  1. Check out to temp branch:
git checkout --orphan temp_branch

--orphan : Create a new orphan branch. The first commit made on this new branch will have no parents and it will be the root of a new history totally disconnected from all the other branches and commits.

  1. Add all the files:
git add -A
  1. Commit the changes:
git commit -am "Initial commit"
  1. Delete the old branch:
git branch -D master
  1. Rename the temp branch to master:
git branch -m master
  1. Finally, force update to our repository:
git push -f origin master