Delete or remove all history, commits, and branches from a remote Git repo?
git
Solution
You might want to try pushing an empty local repo with the `--mirror` flag (emphasis mine):
--mirror
Instead of naming each ref to push, specifies that all refs under refs/ (which includes but is not limited to `refs/heads/`, `refs/remotes/`, and `refs/tags/`) be mirrored to the remote repository. Newly created local refs will be pushed to the remote end, locally updated refs will be force updated on the remote end, and deleted refs will be removed from the remote end. This is the default if the configuration option `remote.<remote>.mirror` is set.
If your repo is on GitHub, you'll get this error if `master` is set to the default branch when trying to push:
$ 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 got around this by making an initial commit, then pushing.
Obligatory Warning: this will, of course, completely wipe out all of your history and commits in your remote repo—all references, all branches, all tags, etc. Make sure this is actually what you want to do. Of course, you can always make a backup clone of your remote repo before doing this, in case you want to keep it around for whatever reason.
Also note that none of the commits will actually be deleted right away. They'll just become dangling commits, meaning that they're not reachable from a branch. Eventually they'll get garbage collected by Git repos, but if you have access to your remote repo, you can manually start the garbage collection with `git gc`.
Problem
I've read and tried lots of Git command recommendations and discussion, going on over several days now. It appears that there really is no simple, comprehensive way to make a remote Git repo completely empty -- no branches, no refs, no objects, no files, no nothing. Yes, I recognize that one could delete and recreate the repo -- if one had that kind of permissions on the origin (which I don't), but that is not the point. How is it done? What combination of Git commands will actually do this, leaving the repo in a virgin state ready to receive whatever we wish to push into it, and with essentially no size (or the minimal size of a virgin repo)? Please don't tell me this shouldn't be done, or that we have to inform all users, etc. I know all that. I just want to start completely fresh.