¿Cómo usar libgit2sharp para crear una nueva twig de local a remota?

Quiero crear y eliminar una twig en git usando libgit2sharp. Se me ocurrió este código pero arroja un error en repo.Network.Push(localBranch, pushOptions);

 using (var repo = new Repository(GIT_PATH)) { var branch = repo.CreateBranch(branchName); var localBranch = repo.Branches[branchName]; //repo.Index.Stage(GIT_PATH); repo.Checkout(localBranch); repo.Commit("Commiting at " + DateTime.Now); var pushOptions = new PushOptions() { Cnetworkingentials = cnetworkingentials }; repo.Network.Push(localBranch, pushOptions); // error branch = repo.Branches["origin/master"]; repo.Network.Push(branch, pushOptions); } 

El post de error es The branch 'buggy-3' ("refs/heads/buggy-3") that you are trying to push does not track an upstream branch.

Intenté search este error en Internet, pero ninguna solución que encontré podría solucionar el problema. ¿Es posible hacer esto usando libgit2sharp?

Tienes que asociar tu sucursal local con un control remoto contra el que quieras presionar.

Por ejemplo, dado un control remoto de "origin" ya existente:

 Remote remote = repo.Network.Remotes["origin"]; // The local branch "buggy-3" will track a branch also named "buggy-3" // in the repository pointed at by "origin" repo.Branches.Update(localBranch, b => b.Remote = remote.Name, b => b.UpstreamBranch = localBranch.CanonicalName); // Thus Push will know where to push this branch (eg. the remote) // and which branch it should target in the target repository repo.Network.Push(localBranch, pushOptions); // Do some stuff .... // One can call Push() again without having to configure the branch // as everything has already been persisted in the repository config file repo.Network.Push(localBranch, pushOptions); 

Note :: Push() expone otras sobrecargas que le permiten proporcionar dinámicamente dicha información sin almacenarla en la configuration.