Reboot Your Git Repo To Fresh State

back to tech articles
Git 1.7


I want to remove all commits and history from the repository and start again, as it were, with a fresh repo. Let’s say this is for efficiency’s sake.


There are a few amazing options available to you with Git, but to be honest, it’s best to just start again. It’s not as scary as you may think.

$ cd /var/public_html/mysite
$ vi .gitignore

This is a good chance to edit or tidy up the Git ignore file, to prepare what will be committed in the fresh repo. Once you are done, we re-create the repo.

$ rm -rf .git
$ git init
$ git add .
$ git commit

And that is all. You have a fresh Git repo without any commits or messages.


1.) In case you didn’t realise it by this point, this will delete ALL your Git history (the main reason a repo is used). You need to be certain you want to do this.

2.) ALL branches will be lost and you will end up with a fresh repo with only master branch.

I love Git because of it’s simplicity in execution, but the power behind those simple commands is immense, so BE CAREFUL.

Let’s stay safe out there!

Leave a Reply

Your email address will not be published. Required fields are marked *