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: https://github.com/libgit2/libgit2sharp/issues/466#issuecomment-21076975
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");