0

I would like to reset a repository to its virgin state, so that it is the same as if I had used the "create new repo" button on Github, containing no commits. I don't have permissions to delete the repo and recreate it, is there any other way to make a remote repo contain no commits after it has been pushed once? If I try to push an empty, commit-free repo, I get error: src refspec master does not match any..

EMC
  • 1,560
  • 2
  • 17
  • 31
  • no you can not, that's the whole purpose of version control so people don't play evil when they are leaving their company. ;) – Vishrant Jul 09 '19 at 19:08
  • Maybe you could try pushing a commit that removes all of the files, and then rebasing all the history to it? – Adil B Jul 09 '19 at 20:25
  • 1
    https://stackoverflow.com/a/26000395/2704032 this answer would help – Vishrant Jul 09 '19 at 22:55

1 Answers1

1

It is possible to remove all the commits associated with a repo, but not all of the issues and pull requests. If you need a completely clean repo, you'll have to delete it and restart.

If you just need to remove the commits, you can do so by removing all of the references, by running a command similar to this:

git for-each-ref refs/heads/* refs/tags/* | awk '{print $3}' | xargs -L1 git push -d origin

This will attempt to delete every reference on the server which you have on your system. It will fail for the reference using the default branch, which is usually master.

Then, delete the default branch (in this case, master) using the API (note that you will need to use a personal access token in place of the text TOKEN):

curl -v -u token:TOKEN https://api.github.com/repos/bk2204/test-repo/git/refs/heads/master

You should substitute your own repo instead of bk2204/test-repo. This will delete the last remaining reference, which will leave you without any branches or tags.

Note that the repository will still have references to pull requests, such as refs/pull/1/head, which you cannot delete. If you really need all of those gone, then you'll have to start fresh.

bk2204
  • 64,793
  • 6
  • 84
  • 100