In order to delete files recursively on Git, you have to use the “git rm” command with the “-r” option for recursive and specify the list of files to be deleted. This is particularly handy when you need to delete an entire directory or a subset of files inside a directory.
In order to clean up remote tracking branches, meaning deleting references to non-existing remote branches, use the “git remote prune” command and specify the remote name. In order to find the name of your current configured remotes, run the “git remote” command with the “-v” option.
If you commit sensitive data, such as a password or SSH key into a Git repository, you can remove it from the history.
As I explain in this answer to Delete or remove all history, commits, and branches from a remote Git repo?, you can also achieve the same thing as Ceilingfish's answer (i.e. delete all references/branches/tags in the remote repo) by doing the following:
Create new empty repo with 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 origin:
git remote add origin <url-to-remote>
Mirror push to remote:
git push origin --mirror
That will delete all references/branches/tags in your remote repo, and any dangling commits will probably be garbage collected eventually. From the official Linux Kernel Git documentation for git push
(emphasis mine):
--mirror
Instead of naming each ref to push, specifies that all refs under
refs/
(which includes but is not limited torefs/heads/
,refs/remotes/
, andrefs/tags/
) be mirrored to the remote repository. Newly created local refs will be pushed to the remote end, locally updated refs will be force updated on the remote end, and deleted refs will be removed from the remote end.
You can delete a branch from a repository remote like this
git push origin :branchname
if you've got any tags you can delete them like this:
git push origin :refs/tags/tagname
This is assuming you have a remote set up to github called origin
This will leave the local tags / branches on your computer, though.
This is what I have done
git rm -r -f -q
git commit
git push
Then you have to manually delete the files, git rm remove the files from the repo but not from the file system
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With