10 Jan 20201 min read

Clear git history

Everyone knows it's important to always use git repository, even while working with just a local project. Usually though, we want to keep everything on remote repository so we do not lose our whole work by an accident.

After a while though, there might be lots of commits and sometimes we do not really want to share every commit message with open source community. Recreating the repo takes time and who likes to waste time?

Usually when I need to get rid of a whole repository history I use those steps:

rm -rf .git

git init
git remote add origin [YOUR REPOSITORY]

git add .
git commit -m "Initial commit 🎉"
git push -u --force origin master

This way we can easily remove all commit history and have a clean one. Just be careful with force pushing as you might not be able to retrieve your data back.