How to clear all commits from remote github repo

I mistakenly pushed hundreds of commits from my local repo to the newly created github repository. How can I clear / delete all these commits on a remote repo so that github refinancing is clean as it was in the beginning? I would also like to play the story of these actions. I would like to do this without affecting my local repo.

I cannot delete a branch, since it is the leading github branch.

+4
source share
2 answers

You can:

- git clone <your github repo> - git reset --hard <an_older_commit> (where you didn't have those huge files) - git push --force origin master 

In this way:

  • Your original local repo is not affected (and you can fix it so you don't click these files again)
  • Your remote repeater (GitHub) no longer sees those who make transactions with huge files in it.
  • GitHub will periodically run git gc on its side, completely clearing files without links.

However, OP Martin mentions:

how can i do a reset --hard in position before the first commit?
those. I would like to get repo empty and not rollback to previous commit

In this case, create a new local repo, make the first small commit and push --force , which will commit.
More generally, I always try to have the first small initial commit on the main branch when creating a repo, in order to be able to return to the minimum commit or start a new branch (for unrelated development efforts) from the specified minimum commit.

+10
source
 git push -f REMOTE COMMIT:BRANCH 

For example, to force the master branch on the remote origin to cancel, before committing with id 123456 , you should do

 git push -f origin 123456:master 
+2
source

All Articles