About Resetting Git History on Remote Repository

Resetting Git history (all your history gets removed) is useful when you:

  • accidentally push your secrets or other sensitive information;
  • want to remove large files from the repo;
  • need a cleanup before open sourcing your project or introducing the code to new developers.

Here's how to do that in the terminal:

$ git checkout --orphan temp_branch
$ git add .
$ git commit --message="✨ Reset repository history"
$ git branch --delete --force main
$ git branch --move main
$ git push --force origin main

Force-pushing an orphan branch replaces a remote repository's main branch. This is practically irreversible. While this doesn't immediately delete history files on the remote server, they become inaccessible through normal Git operations and will eventually be removed on Github, Bitbucket, or GitLab during garbage collection.

Tips and Tricks Developer Experience Git