libgit2sharp add tag
Hosch250 (imported from SE)
I need to delete a remote branch, and found this technique:

> git push origin :the_remote_branch

I tried passing it to `Network`s `Push` method in the following forms, but nothing seems to work (`options` is my login credentials):

    _repo.Network.Push(_repo.Network.Remotes["origin"], "origin/:NewBranchForDeletion", options)  
    _repo.Network.Push(_repo.Network.Remotes["origin"], ":NewBranchForDeletion", options)  
    _repo.Network.Push(_repo.Network.Remotes["origin"], ":origin/NewBranchForDeletion", options)
    _repo.Network.Push(_repo.Network.Remotes["origin"], ":refs/remotes/:origin/NewBranchForDeletion", options)
    _repo.Network.Push(_repo.Network.Remotes["origin"], ":refs/remotes/origin/NewBranchForDeletion", options)
    _repo.Network.Push(_repo.Network.Remotes["origin"], "refs/heads/:origin/NewBranchForDeletion", options)
    _repo.Network.Push(_repo.Network.Remotes["origin"], "refs/heads/:NewBranchForDeletion", options)

And a few other options.  I cannot get it to work at all, it returns errors such as (for the ":NewBranchForDeletion" method):

> Not a valid reference "NewBranchForDeletion"

### Update:

Thanks to @Rob for finding me this comment on LibGit2Sharp's repo:

The first option fails with a `NullReferenceException` on `objectish`, and using `string.Empty` for `objectish` results in the error mentioned above.  The second option is what I am trying, except I am using the version with HTTPS validation:

    repo.Network.Push(repo.Remotes["my-remote"], objectish: null, destinationSpec: "my-branch");
    // Or using a refspec, like you would use with git push...
    repo.Network.Push(repo.Remotes["my-remote"], pushRefSpec: ":my-branch");
Top Answer
nulltoken (imported from SE)
As stated in the **[documentation](**, a refspec _"Specif(ies) what destination ref to update with what source object. The format of a <refspec> parameter is an optional plus `+`, followed by the source object <src>, followed by a colon `:`, followed by the destination ref <dst>."_

It also mentions that _"Pushing an empty <src> allows you to delete the <dst> ref from the remote repository."_

Considering these above, using the `void Push(Remote remote, string pushRefSpec)` overload, and passing `:refs/heads/branch_to_delete` as the `pushRefSpec` should do the trick.

This room is for discussion about this question.

Once logged in you can direct comments to any contributor here.

Enter question or answer id or url (and optionally further answer ids/urls from the same question) from

Separate each id/url with a space. No need to list your own answers; they will be imported automatically.