Git: remove remote branch from mirror tree

I built a repository using

git clone --mirror <url> 

I want to delete some deleted 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 

In addition, git branch -D b does not touch the remote control.

Is there a way to remove remote branches from mirror cloning, or do I need to build another clone for this?

+7
source share
2 answers

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 the git repository of any repository - you can even create an empty repository to do this and then delete it.

Of course, you can do this inside the mirror as well, just note that you will see that the branch disappears after git remote prune origin executed.

+3
source

If you clone a repository using --mirror, you will create a bare repository. That means:

"that Git simply contains version control information and working files (without a tree), and it does not contain a special .git subdirectory. Instead, it contains all the contents of the .git subdirectory directly in the main directory itself.".

The mirror option in clone is to make an β€œas is” copy of your current repo, including notes and external links.

Being said, you are doing this on the wrong repo, you must use the original one to make changes, and the mirror will change accordingly.

Answering your question:

Is there a way to remove remote branches from mirror cloning, or do I need to build another clone for this?

I do not know what I know, except that the empty repository cannot be used as non-bare.

Maybe you need a plug, maybe if you explain a little better what you need. In any case, a year has passed since you asked the question.

Here are some related questions and doc:

+3
source

All Articles