11

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?

Penz
  • 5,428
  • 5
  • 31
  • 28

3 Answers3

5

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.

Penz
  • 5,428
  • 5
  • 31
  • 28
3

If you clone a repository using --mirror you will create a bare repository. Which implies:

" that Git just contains the version control information and no working files (no tree) and it doesn't contain the special .git sub-directory. Instead, it contains all the contents of the .git sub-directory directly in the main directory itself.".

The mirror option at clone is ment to make a "as it is" copy of your current repo, including notes and external refs.

Being that said, you are doing it on the wrong repo, you should 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 a mirror clone or do I have to build another clone for that?

Not that i know of, besides a bare repository shoul not be used like a non-bare one.

Maybe what you need it's a fork, maybe if you explain a little better what you need. Anyways, a year has past since you make the question.

Here's some related questions and doc:

Community
  • 1
  • 1
Joako-stackoverflow
  • 506
  • 1
  • 6
  • 16
2

From a bare repo (clone a repository using --mirror option), you can delete branch in mirrored repo and push deletion with --mirror option :

$> git clone --mirror <url>
$> git branch -D branch_to_delete_1
$> git branch -D branch_to_delete_2
$> git push --mirror

It's allow you to delete multiple branches once.

More info : https://git-scm.com/docs/git-push

passionne
  • 56
  • 3