Reset history in git commits
Time travel is complicated and dangerous, but it is the first thing we think to do when we are programming a lot and we want to delete all the history and pretend that nothing happened… in real worl is impossible (until now), but in the world of git this is possible, not highly recommended, but It is a good option when we want to remove all the commits that we have in a repo :S
Why we will should do this?
A real case where this could be used is when we have a private repo, we work a lot and do a lot of commits (someones not very elegant or well done) and we want to leave the repo public with only one commit, something like “initial commit”, this what we can do is:
git checkout --orphan tmp-main
git add -A
git commit -m 'initial commit'
git branch -D main
git branch -m main
git push -f origin main
And tara! everything looks clean, without history of commits :( , but clean and ready to public use.