libgit2sharp删除远程分支 [英] libgit2sharp remove remote branch

查看:117
本文介绍了libgit2sharp删除远程分支的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在本地和远程删除分支. 我的代码:

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

using (var repository = new Repository(path))
{
    var remote = repository.Network.Remotes["origin"];
    var options = new PushOptions();
    var credentials = options.CredentialsProvider = GetUserCredentialsProvider();
    options.CredentialsProvider = credentials;
    string pushRefSpec = @"refs/heads/:{0}".FormatWith(branch);
    repository.Network.Push(remote, pushRefSpec);
    repository.Branches.Remove(repository.Branches[branch]);
}

但是我收到401错误(未经授权"). 这是因为分支名称中存在:".

But I get the 401 error ("Unauthorized"). And it's because of the presence of the ":" in the name of the branch.

但是我读到它们是必需的,因为它们就像本地git中的"--delete"一样.

But I read that they are necessary, because of they are like "--delete" in native git.

感谢您的帮助!

推荐答案

这失败,并显示401 Unauthorized错误,因为它是未经授权的.要解决此错误,您只需将包含凭据的options传递给Push()方法:

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.

这篇关于libgit2sharp删除远程分支的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆