How to delete all commit history in GitHub?

How to delete all commit history in GitHub?

Deleting the commit history

1. 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

2. Add Files to Branch

Now add all files to the newly created branch and commit them using the following commands.

git add -A
git commit -am "the first commit"

3. Delete master Branch

Now you can delete the master branch from your git repository.

git add -A
git commit -am "the first commit"

4. Rename Current Branch

After deleting the master branch, let’s rename the newly created branch name to master.

git branch -m master

5. 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

That’s it. You have successfully removed the commit history on a Git repository.

Happy Coding!