gpt4 book ai didi

c# - libgit2sharp 删除远程分支

转载 作者:太空狗 更新时间:2023-10-29 14:05:29 25 4
gpt4 key购买 nike

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

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 错误(“未经授权”)。这是因为分支名称中存在“:”。

但我读到它们是必需的,因为它们就像原生 git 中的“--delete”。

感谢您的帮助!

最佳答案

由于未授权,因此失败并出现 401 未授权错误。要修复此错误,您只需将包含您的凭据的 options 传递给 Push() 方法:

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

这为我解决了这个问题。

关于c# - libgit2sharp 删除远程分支,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34307963/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com