I built a repository using
git clone --mirror <url>
I want to remove some remote branches, but I get the following:
$ git push origin :b
error: --mirror can't be combined with refspecs
... or
$ git push --delete b
fatal: --delete doesn't make sense without any refs
Also, git branch -D b
does not touch the remote.
Is there a way to remove remote branches from a mirror clone or do I have to build another clone for that?
Steps to delete remote Git branchesIssue the git push origin –delete branch-name command, or use the vendor's online UI to perform a branch deletion. After the remote branch is deleted, then delete the remote tracking branch with the git fetch origin –prune command.
Instead of using the git branch command that you use for local branches, you can delete a remote branche with the git push command. Then you specify the name of the remote, which in most cases is origin . -d is the flag for deleting, an alias for --delete . remote_branch_name is the remote branch you want to delete.
How to Delete a Branch Remotely. You'll often need to delete a branch not only locally but also remotely. To do that, you use the following command: git push <remote_name> --delete <branch_name>.
git fetch --prune is the best utility for cleaning outdated branches. It will connect to a shared remote repository remote and fetch all remote branch refs. It will then delete remote refs that are no longer in use on the remote repository.
In fact, you can delete any branch of any repository without even cloning it:
git push <url> +:refs/heads/b
The only caveat is that you must be inside a git repository, any repository - you can even create an empty repository to do just that and then delete it.
Surely enough, you can do that inside the mirror too, just note that you will only see the branch go away after doing a git remote prune origin
.
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