Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to clean all commits from remote github repo

Tags:

git

github

I had by mistake pushed hundreds of commits from my local repo to a newly created github repo. How can I clean/remove all these commits on the remote repo so that github repo is clean as it was in the start? I would like also to lose history on those actions. I would like to do that without affecting my local repo.

I cannot delete the branch as it is the github master branch.

like image 475
Martin Avatar asked Jul 27 '11 10:07

Martin


1 Answers

You could:

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

That way:

  • Your initial local repo isn't affected (and you can fix it in order to not push again those files)
  • your remote (GitHub) repo doesn't see anymore those commits with the huge files in it.
  • GitHub will run a git gc on its side periodically, cleaning completely the unreferenced files.

However the OP Martin mentions:

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

In that case, create a new local repo, make a first small commit, and push --force that commit.
More generally, I always try to have a first small initial commit on master branch when creating a repo, in order to be able to get back to a minimal commit, or to start a new branch (for an unrelated development effort) from said minimal commit.

like image 120
VonC Avatar answered Oct 14 '22 19:10

VonC