Peter Mekhaeil

Git Remove All Commits

Clean up history from a repository by removing the git commits and replacing it with a new single commit.

  1. Create a temporarily branch disconnected from all the other branches and commits:
git checkout --orphan temp_branch
  1. Add the files to new temporarily branch:
git add -A
  1. Commit the changes:
git commit -am "First commit"
  1. Delete the main branch:
git branch -D master
  1. Rename temporarily branch to the main branch:
git branch -m master
  1. Force push the new main branch:
git push -f origin master