Reset a git remote (--bare) repo to 'Initial commit'
Sat Aug 6 05:30:09 2011
I found a situation where I wanted to totally reset a remote repository and although deleting it and then recreating it using --bare usually does the trick, the server set up shared dependances that would have caused more trouble if I had done that. So the only option was to completely reset the repo and effectively wipe clean any past history.
In actual fact it is simpler than it sounds. Create a local repo using
git init, add some files using
git add * (where you can also replace the * with the particular name of a file/files). Commit the changes, i.e.
git commit -m "Initial commit" and then add the remote url using
git remote add origin remote_url_here.
Now all you have to do it push to the master branch of your remote to overwrite everything. However, simply using the command
git push origin master will most likely fail due to the fact that content already exits. So here's what you do. Use
git push --force.
That should give the desired results and you'll find that the existing remote will update and feel much fresher indeed. However, BE WARNED that this deletes everything as you'll see if you run
git log on the remote.