libgit2sharp remove remote branch

前端 未结 2 1461
长发绾君心
长发绾君心 2021-01-20 22:05

I want to delete a branch locally and remote. My code:

using (var repository = new Repository(path))
{
    var remote = repository.Network.Remotes[\"origin\         


        
相关标签:
2条回答
  • 2021-01-20 22:27

    I just figured out the solution from the libgit2 sourcecode.

    repository.Network.Push(origin, "+:/refs/heads/to-remove-branch")
    

    The part +:/refs/heads/to-remove-branch of the refspec specifies that the remove command is forced, else just use :/refs/heads/to-remove-branch

    Source: https://github.com/libgit2/libgit2/blob/master/tests/online/push.c

    0 讨论(0)
  • 2021-01-20 22:33

    This is failing with a 401 Unauthorized error because it is unauthorized. To fix this error, you just need to pass the options containing your credentials to the Push() method:

    repository.Network.Push(remote, pushRefSpec, options)
    

    That fixed this problem for me.

    0 讨论(0)
提交回复
热议问题