在仓库上设置上游 [英] Setting upstream on a repo
问题描述
我正在尝试使用libgit2sharp
从remote
中拉出master
分支.
I am trying to pull the master
branch from a remote
using libgit2sharp
.
有时我必须将remote
更改为其他网址,并从该remote
中提取.
当我更改remote
并尝试到pull
时,出现此错误:
Sometimes I have to change the remote
to a different url and pull from that remote
.
When I change the remote
and try to pull
I get this error:
There is no tracking information for the current branch
我知道我必须执行git branch --set-upstream-to=origin/master master
来使用git来解决此问题,但是我想知道如何使用libgit2sharp
来做到这一点?
I know I have to do git branch --set-upstream-to=origin/master master
to fix this issue using git, but I wonder how can I do the same with libgit2sharp
?
推荐答案
给出mybranch,一个Branch
实例,该实例已经配置为跟踪origin
远程服务器中的分支.
Given mybranch, a Branch
instance, which is already configured to track a branch in the origin
remote.
如果您愿意做的就是将远程服务器重新配置(同时保留本地和远程跟踪分支配置),再配置为另一个(例如"myOtherRemote"),那么下面的代码应该可以解决问题. /p>
If all you're willing to do is reconfigure the remote (while keeping the local and remote tracking branch configuration), to another one (eg. "myOtherRemote"), then the following piece of code should do the trick.
repo.Branches.Update(myBranch, b => b.Remote = "myOtherRemote");
这篇关于在仓库上设置上游的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!