richardd
richardd

Reputation: 128

Libgit2sharp, Pushing a specific branch to new remote

I am writing a dotnet api to clone from github, then push a specific branch to AWS codecommit using the Libgit2sharp library.

Problem: I can't seem to get it to push my specified branch to codecommit, it always seems to push what is set to HEAD. I don't know how to change the HEAD, or even know if this is the issue.

Code Snippet:

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);

Any help appreciated... Cheers

Upvotes: 1

Views: 292

Answers (1)

VonC
VonC

Reputation: 1328602

Try and use a 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>.

In your case:

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

Upvotes: 1

Related Questions