Lothre1
Lothre1

Reputation: 3853

Is there a way to completely erase my remote git repository?

I know that it's possible. I've made that long time ago but until now I couldn't find any solution to properly empty a remote repository.

My goal is: 1. Empty everything on remote repo 2. Commit all my files from local repo as a new starting project

Upvotes: 1

Views: 154

Answers (2)

janos
janos

Reputation: 124648

How about just creating a fresh new repository, add a remote that points to the one that you want to wipe out, and force update?

cd /folder/with/new/files
git init
git add .
git commit -m 'added files'
git remote add origin URL_TO_REPO_TO_WIPE
git push -u origin master -f

UPDATE

To really wipe out everything, there is one more step: delete all other remote branches except master:

git fetch origin
git branch -r | cut -d/ -f2- | grep -v master | xargs -i{} git push origin :{}

I suppose the old commits that are now unreferenced will still survive this. To be honest I don't know the details of how that works. I think orphaned commits should get deleted at some point when the remote repo is periodically compacted, I think GitHub does that, for example. If it's important to you to really wipe out all stale references, then you should find out from the host of your repo. (If you own the server then it would have been easiest to recreate the repo yourself, of course, and then all this discussion here is pointless...)

For @zerkms

I tested that commits are wiped out locally using these commands:

cd /some/repo
git clone --bare . /tmp/oldrepo.git
git init /tmp/newrepo
cd /tmp/newrepo
date > date.txt
git add .
git commit -m start
git remote add origin /tmp/oldrepo.git
git push origin -f
cd ..
git --git-dir oldrepo.git rev-list --all

This last step shows only the one commit I force-pushed. But as I explained above, I'm pretty sure some orphaned commits are still hanging there, as I think you are suggesting too. If you could tell me how to confirm those that would be nice, and then maybe I could improve my answer.

Upvotes: 1

willeM_ Van Onsem
willeM_ Van Onsem

Reputation: 476503

It depends on whether the remote accepts fast-forwards and modifying history.

It that case you can make a clone. Be careful, use a new temporary local repository (while maintaining the old one), otherwise the local repository will be cleared as well.

git clone url folder
cd folder

remove everything from the entire history

git filter-branch --force --index-filter 'git rm --cached --ignore-unmatch *' --prune-empty --tag-name-filter cat -- --all

and force a push to the remote

git push -f origin

Some remotes however (like BitBucket) allow the administrator to protect branches against historical rewrites or removal, in that case the remote will throw an error. From the moment you use a remote, you will have to thrust that the remote will not abuse the information you provide.

Upvotes: 2

Related Questions