Libgit2sharp,将特定的分支推送到新的遥控器

时间:2020-03-28 00:33:03

标签: git .net-core libgit2sharp aws-codecommit

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

  • 我在gitHubRepo中有两个分支,起源/发行版和起源/重构。
  • 起源/发行版是DEFAULT git分支
  • 我想克隆gitHubRepo,并推动origin / refactor分支进行代码提交

问题: 我似乎无法让它将我指定的分支推送到代码提交,它似乎总是能将设置为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);

任何帮助表示赞赏...干杯

1 个答案:

答案 0 :(得分:1)

尝试并使用complete refsepc when pushing

<refspec>参数的格式是可选的加+,后跟源对象<src>,后跟冒号:,后跟目标ref { {1}}。

在您的情况下:

<dst>