Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git clear remote repository

Tags:

git

If I push a bad initial commit (or more than one) to a remote repository and want to just clear it / destroy it - can I do it by a command?

It's important to totally remove it from server so it doesn't use disk space.

E.G. Today I pushed a whole Visual Studio project with included dlls, sdfs and so on. Firstly this files are quite big, secondly some of them are modified by VS of other developers and than can't be merged. This made me google a little bit and I found out these files should be ignored. But the first commit already clutters my repository. I want to remove this and free the disk space.

It's possible to remove git repo and add it again via host's website (assembla), but this doesn't sound like solution to me.. Is there a more professional way?


UPDATE:

I tried suggestions from the answer below but it didn't work: 'git push -f' 'git push --force' 'git push origin -f' 'git push origin --force' resulted in:

$ git push --force
Counting objects: 19, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (19/19), done.
Writing objects: 100% (19/19), 6.85 KiB, done.
Total 19 (delta 3), reused 0 (delta 0)
remote: error: denying non-fast-forward refs/heads/master (you should pull fir
)
To [email protected]:xxxxx.git
 ! [remote rejected] master -> master (non-fast-forward)
error: failed to push some refs to '[email protected]:xxxxx.git'
like image 344
Andrzej Gis Avatar asked Sep 17 '11 00:09

Andrzej Gis


People also ask

How do I remove all files from a remote git repository?

In order to delete files recursively on Git, you have to use the “git rm” command with the “-r” option for recursive and specify the list of files to be deleted. This is particularly handy when you need to delete an entire directory or a subset of files inside a directory.


1 Answers

You can force push the "correct" repo with git push -f. Depending on the host, the loose objects will be cleaned up when git gc is ran. update: According to this you can't force the git gc in assembla.

If you want them cleaned up immediately and assembla doesn't allow you to force a git gc, the other option is to delete the repo and push a new one.

In addition, as Ryan stated in the comments, be sure to let everyone know that may have cloned the repo, that you re-wrote history.

like image 86
Andy Avatar answered Oct 06 '22 13:10

Andy