I have a repository.

How can I delete my old commits via terminal? My SSH key is uploaded.

(I'm using github pages, that's why version tracking is not important, don't want to waste Github's storage)

  • Hi, you cannot remove old commits on a public repository. You either create a private repo or create a new account.
    – KC Chai
    Jun 12, 2015 at 5:06

3 Answers 3


Deleting the .git folder may cause problems in your git repository. If you want to delete all your commit history but keep the code in its current state, it is very safe to do it as in the following:


git checkout --orphan latest_branch

Add all the files

git add -A

Commit the changes

git commit -am "commit message"

Delete the branch

git branch -D master

Rename the current branch to master

git branch -m master

Finally, force update your repository

git push -f origin master

PS: this will not keep your old commit history around.


You have an really good answer for that here: https://stackoverflow.com/questions/448919/how-can-i-remove-a-commit-on-github

And I quote

Note: please see alternative to git rebase -i in the comments below—

git reset --soft HEAD^

First, remove the commit on your local repository. You can do this using git rebase -i. For example, if it's your last commit, you can do git rebase -i HEAD~2 and delete the second line within the editor window that pops up.

Then, force push to GitHub by using git push origin +master.

See Git Magic Chapter 5: Lessons of History - And Then Some for more information (i.e. if you want to remove older commits).

Oh, and if your working tree is dirty, you have to do a git stash first, and then a git stash apply after.

Hope this help you :)

==== EDIT ====

Actually I just reread the post I linked to and specially the comment "word of caution 2" https://stackoverflow.com/questions/448919/how-can-i-remove-a-commit-on-github

From that I learned that git seems create a new commit and moving the pointer to it, rather than deleting it when using force push. That is if someone already have the SHA1 of your commit, they can still access it. So when taking this into consideration, I must recommend that you do as Tomasz Klim suggested.

  1. Create new repository.
  2. Copy all files to it.
  3. Destroy old repository.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .