Is it possible to completely empty a remote Git repository?
I think you may have an XY problem. You don't actually need to get the remote repository back into its original state in order to start over; you simply need to start over locally, then force-push that to the remote.
# create a new repository that has the initial commit that you want
mkdir foo; cd foo; git init; ...; git commit
# set up a remote
git remote add origin <url-of-remote>
git branch --set-upstream master origin/master
# push your new history
git push -f
# delete obsolete remote branches
git push origin :deprecated-branch
The remote repository never returns to a no-commits state, but it ends up where you want it, and that's all that matters!
(Under the hood, the old commits are actually still in the remote repository, but they're left dangling, with no refs pointing to them. They'll be automatically removed when git gc --auto
is triggered by a push at some point.)
If you really, really want to empty it for some reason, you can set receive.denyDeleteCurrent
in the remote repository, and push-delete all branches, including the current one. I don't see why you actually need to, though!
Below steps will do it easily, Be careful to take master backup in case needed.
mkdir reset
cd reset
git init
touch README.md
git add .
git commit -m 'Initial commit'
git remote add origin [email protected]:XXX/xxx.git
git push --force --set-upstream origin master