Reputation:
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"
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");
Upvotes: 10
Views: 1090
Reputation: 67669
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.
Upvotes: 5