Libgit2sharp,将特定分支推送到新远程

Libgit2sharp, Pushing a specific branch to new remote

我正在编写一个 dotnet api 以从 github 克隆,然后使用 Libgit2sharp 库将特定分支推送到 AWS codecommit。

问题: 我似乎无法让它将我指定的分支推送到代码提交,它似乎总是将设置为 HEAD 的内容推送。我不知道如何更改 HEAD,甚至不知道这是否是问题所在。

代码片段:

var baseRefBranch = gitHubRepo.Branches[$"origin/refactor"];
if (baseRefBranch == null) throw new Exception("refactor branch was null...");

logger.LogInformation($"Checking out branch: {baseRefBranch.CanonicalName}");
Commands.Checkout(gitHubRepo, baseRefBranch);

logger.LogInformation($"Update branch {baseRefBranch.CanonicalName}, set remote name {codeCommitRemote.Name}, set upstreamBranch to {baseRefBranch.CanonicalName}");
        gitHubRepo.Branches.Update(baseRefBranch,
            b => b.Remote = codeCommitRemote.Name,
            b => b.UpstreamBranch = baseRefBranch.CanonicalName);

var refSpec = $"+{baseRefBranch.CanonicalName}";
logger.LogInformation($"Trying to push to remote: {codeCommitRemote.Name}, refSpec: {refSpec}");
gitHubRepo.Network.Push(codeCommitRemote, refSpec, pushOptions);

感谢任何帮助...干杯

尝试使用 complete refsepc when pushing

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>.

你的情况:

+refs/heads/refactor:refs/heads/refactor