How to Delete All Git Commit History

Since the launch of my website, the structure has always had various issues, and the two themes released along with it also had many aspects that left much to be desired. Thankfully, a major update some time ago addressed many awkward elements and removed a lot of unnecessary content. This got me thinking: why not take it a step further and delete all the git commit history as well?

Deleting the entire git commit history is not a common scenario, and I don't recommend doing this for collaborative open-source projects. Even for personal projects, it's usually better to keep some important commits, as you never know when you might need to revisit them to regain lost development insights. (Or if you're feeling nostalgic, you might even look back at old commits and reminisce about the journey of creating your project.) If you're interested in cleaning up only some of your commits, I suggest checking out this article from GitLab: "How (and why!) to keep your Git commit history clean". I won't go into detail on that here.

The main reason I wanted to clear out the commit history was that my personal project had too many irrelevant commits. Additionally, for a site like this, keeping commit history seems unnecessary. I plan to treat "GitHub Pages" simply as a content hosting platform from now on, without tracking changes anymore. I followed this guide I found online to wipe the commit history: "how to delete all commit history in github?"

Here are the steps (identical to those in the original link—this article is just a record; refer to the original source for more details):

# checkout a temporary branch
git checkout --orphan tmp_branch

# add all files
git add -A

# commit
git commit -am "first commit"

# delete the master branch
git branch -D master

# rename the current branch to master
git branch -m master

# force push to the remote repo
git push -f origin master

After this, my repo only has a single commit left. The feeling of cleaning it all up is so satisfying! It's like emptying the recycle bin—very refreshing.

That said, I still encourage caution when deleting commit history. I hope you find as much joy in decluttering as I did! (^u^)