In this article i am showing how to clear Git history by removing all commits.
You may need this if you want to delete sensitive data from the history of Git commits.
After such cleanup you will have the latest version of your Git repository, but with the one commit only.
Be aware that after resetting all the history of changes in your Git repository will be deleted as well.
Cool Tip: Made a mistake? Undo last Git commit! Read more →
Clear Git History
Create a temporary branch and
$ git checkout --orphan temp_branch
||Create a branch in a
Add all files to the temporary branch and commit the changes:
$ git add -A $ git commit -am "The first commit"
$ git branch -D master
Rename the temporary branch to
$ git branch -m master
Forcefully update the remote repository:
$ git push -f origin master
Cool Tip: Revert a file to the previous commit! Read more →
24 Replies to “Git – Remove All Commits – Clear Git History (Local & Remote)”
This was perfect. Thanks!
Thanks, it works like a charm 🙂
Beautiful, thanks so much
Thanks this really helped
Thank you. That worked perfect!
Worked like a charm, thanks a lot !! 🙂
Most excellent! Many thanks!
Wow! This is a life saver!
Wow! This is the bomb! Many Thanksssss!
Super helpful, thanks!
Thanks, worked for me. Been looking for this for a while.
Much much thanks!
Amazing thank you!
It works perfect with Codecommit! Thanks!
Simple & efficient.
error: refname refs/heads/temp_branch not found
It works, but it still leaves the old versions of files in the .git directory
Saved my day!