This tutorial will help you to delete commit history from your local git repository and remote git repository hosted on Github, Gitlab, Bitbucket or any other git hosting. In this repository, you will remove the local master branch and create a new master branch. Finally, push changes to the remote git repository.
Delete Commit History in Github Repository
Follow the below steps to complete this task.
Warning: This will remove your old commit history completely, You can’t recover it again.
- Create Orphan Branch – Create a new orphan branch in git repository. The newly created branch will not show in ‘git branch’ command.
git checkout --orphan temp_branch - Add Files to Branch – Now add all files to newly created branch and commit them using following commands.
git add -A git commit -am "the first commit" - Delete master Branch – Now you can delete the master branch from your git repository.
git branch -D master - Rename Current Branch – After deleting the master branch, let’s rename newly created branch name to master.
git branch -m master - Push Changes – You have completed the changes to your local git repository. Finally, push your changes to the remote (Github) repository forcefully.
git push -f origin master
Reference: http://stackoverflow.com/questions/13716658/how-to-delete-all-commit-history-in-github
Great! Thanks 🙂
Salute!
Thank you!
i love you. i couldnt remove sensitive data from the repo because i burried it with more commits and nothing else worked until i found this <3
Thanks, this helped. However, the remote server still keeps the old commits and they may be accessible, e.g. from web GUI or by commit hash. This is a problem if you accidentally commited a password.
The fix is to ssh into the bare repo and run `git gc –prune=now`. That should drop them.
Works like a charm. Thank you!
Thanks!
Excellent.
Thanks
Thanks.