Git hack[1]: Remove commit history.

Git hack[1]

Sometimes you work on a project, you accidentally push some credential information in the remote repository.

credential information means API token, User Email password which used for the test, SHA key, Database host username password, etc.

Now what?

You can commit again by removing those credential info from the file and you think no one can see, here you will make mistake again.

Many crawling bots will crawl the git repo every time whether or repo public or on that case, it's making very risky for your project repo.

This very acceptable solution. you can remove commit by git reset --hard <sha1-commit-id> and git push origin HEAD --force

but you have done many commits after this issue. SO it will be very hard for you to take backup and remove commit and force push again.

If you are human like me, you don't care about all those commit records you just need to flush all commit history anyhow possible but don't know the possible solution then this story is for you. Even if you do not like me also for you too. Maybe it might help you in the future. :D

Remember this will remove your old commit history completely, You can’t recover it again.

You have to create an orphan branch by

git checkout — orphan orphan_branch

then add all file and commit

git add .
git commit -m "new commit"

delete the branch you want to delete in my case its master.

git branch -D master

rename the current branch master

git branch -m master

then push the branch

git push -f origin master

see? how

Love to work with new technologies, explore new challenges and watch Movies & Anime

Love to work with new technologies, explore new challenges and watch Movies & Anime