Andrei Pall

Linux Software Engineering

How to Delete Commit History on Github

This tutorial will help you to delete commit history from your local git repository and remote git repository hosted on Github. In this repository, you will remove the local master branch and create a new master branch. Finally, push changes to the remote git repository.

Follow the below steps to complete this task:

  1. Create Orphan Branch - Create a new orphan branch in git repository. The newly created branch will not show in 'git branch' command.
  2. git checkout --orphan temp_branch
  3. Add Files to Branch - Now add all files to newly created branch and commit them using following commands.
  4. git add -A
    git commit -am "the first commit"
  5. Delete master Branch - Now you can delete the master branch from your git repository.
  6. git branch -D master
  7. Rename Current Branch - After deleting the master branch, let’s rename newly created branch name to master.
  8. git branch -m master
  9. Push Changes - You have completed the changes to your local git repository. Finally, push your changes to the remote (Github) repository forcefully.
  10. git push -f origin master