Delete all files and history from a remote Git repository without deleting the repo itself

I would appreciate if someone could tell me how I can delete every file / folder in my git repository without actually deleting the repository itself. I also want to delete the entire history associated with these files.

+49
git
Mar 19 '11 at 18:09
source share
3 answers

You can delete a branch from remote storage, for example

git push origin :branchname 

if you have tags, you can remove them as follows:

 git push origin :refs/tags/tagname 

It is assumed that you have remote setup before github named origin

This will result in local tags / branches on your computer.

+9
Mar 19 '11 at 18:27
source share

How will I explain in this answer on Delete or delete all history, commits and branches from a remote Git repo? , you can also achieve the same as the Reply to ceiling @ (i.e. remove all links / branches / tags in the remote repo) by doing the following:

  • Create a new empty repo with the initial commit:

     mkdir new cd new echo "This is the README" > README.md git init git add . git commit -m "Add README.md (initial commit)" 
  • Add remote repo as source:

     git remote add origin <url-to-remote> 
  • Press the mirror on the remote control:

     git push origin --mirror 

This will delete all links / branches / tags in the remote repo , and any dangling commits are likely to be garbage collected. From the official Linux Git kernel documentation for git push (highlighted by me):

 --mirror 

Instead of calling each ref for push, it indicates that all refs under refs/ (which includes but is not limited to refs/heads/ , refs/remotes/ and refs/tags/ ) are mirrored to the remote repository. New local links will be redirected to the remote end, locally updated links will be forcibly updated at the remote end, and deleted links will be deleted from the remote end .

+72
Aug 11 '13 at
source share

This is what I did

git rm -r -f -q

git commit

git click

Then you need to manually delete the files, git rm delete the files from the repo, but not from the file system

+5
Jan 24 '12 at 10:10
source share



All Articles