Tech BlogBrand Name

Deleting your git commit history without removing repo on Github/Bitbucket

When you have just found out that you or a fellow team mate has committed sensitive data into your Github repo. What do you do?

If you do not have hundreds of commits already. You can follow the steps mentioned below.

WARNING: This should be used with care! It also removes the configuration of the repo.

Step 1

Remove all history

$ cd myrepo
$ rm -rf .git

Step 2

Init a new repo

$ git init
$ git add .
$ git commit -m "Removed history, due to sensitive data"

Step 3

Push to remote

$ git remote add origin github.com:yourhandle/yourrepo.git
$ git push -u --force origin master

Source: StackOverflow

© 2021 Will & Skill