Delete or delete all history, commits and branches from a remote Git repository?

I read and tried many of the recommendations and discussions of the Git team that have been going on for several days. It seems that in fact there is no simple and comprehensive way to make the remote Git repository completely empty - there are no branches, no links, no objects, no files, nothing .

Yes, I admit that you can delete and recreate the repo - if you had such rights to the origin (which I do not have), but it is not. How it's done? What combination of Git commands will actually do this, leave the repo in a virgin state , ready to accept what we want to insert into it, and with almost no size (or minimum size of a virgin repo) ?

Please do not tell me that this should not be done, or that we should inform all users, etc. . I know all this. I just want to start a whole new one .

+20
git
Aug 07 '13 at 20:15
source share
2 answers

You might want to try an empty local repo with the --mirror flag (my selection):

 --mirror 

Instead of calling each ref for push, it indicates that all refs in refs / (which includes but is not limited to refs/heads/ , refs/remotes/ and refs/tags/ ) are mirrored to the remote repository. Newly created local links will be moved to the remote end, locally updated links will be forced to be updated at the remote end, and deleted links will be deleted from the remote end . This is the default value if the remote.<remote>.mirror configuration parameter is remote.<remote>.mirror .

If your repo is on GitHub, you will get this error if the default branch is set when you try to press master :

 $ mkdir practice; cd practice; $ git init; git remote add origin git@github.com:user/practice.git; $ git push origin --mirror remote: error: refusing to delete the current branch: refs/heads/master To git@github.com:user/practice.git ! [remote rejected] master (deletion of the current branch prohibited) error: failed to push some refs to 'git@github.com:user/practice.git' 

I circumvented this by making an initial commit, and then clicking.

Mandatory warning : this, of course, will completely destroy your entire history and commit your remote repo: all links, all branches, all tags, etc. Make sure that this is actually what you want to do. Of course, you can always make a backup clone of your remote repo before doing this if you want to keep it for any reason.

Also note that none of the commits will be deleted immediately. They will just become chatty commits, which means that they are inaccessible from the branch. In the end, they will get garbage collected by Git repositories, but if you have access to the remote repo, you can manually start garbage collection using git gc .

+31
Aug 07 '13 at 20:27
source share

You cannot do this. The best you can do is remove all links and hope the server runs git gc and has settings for prune objects that have no links. It depends on the server configuration.

It usually takes 14 days to delete objects on git gc. However, this object will not be cloned if you try to clone the repository.

You already have a good answer on how to do a hack to remove all links. It works, and your repo will seem to you because it is "fresh." However, it is not.

0
Aug 08 '13 at 0:44
source share



All Articles