git 无法跟踪远程分支 - 无法识别来源/开发

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17210624/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 08:39:45  来源:igfitidea点击:

Can't track remote branch - doesn't recognize origin/develop

git

提问by Shai Reznik - HiRez.io

I have git 1.8.3 and a repo with 'master' and 'develop' branches.

我有 git 1.8.3 和一个带有“master”和“develop”分支的仓库。

From my local 'develop' branch, I'm trying to do the following command -

从我本地的“开发”分支,我正在尝试执行以下命令 -

git branch -u origin/develop

git branch -u origin/develop

and I get an error of

我得到一个错误

error: the requested upstream branch 'origin/develop' does not exist

error: the requested upstream branch 'origin/develop' does not exist

When I check git branch -rI see only origin/master

当我检查时,git branch -r我只看到origin/master

I'm trying to find a way to make my system recognize that there is also a origin/developand can't find any solution that works.

我试图找到一种方法让我的系统认识到还有一个origin/develop并且找不到任何有效的解决方案。

回答by Jan Krüger

  • If the branch developalready exists in the remote repository, use git fetchto update your "remote-tracking branches" (local mirrors).
    • This requires that the fetch refspec is set correctly (in .git/configin the section for your remote); the default is fetch = +refs/heads/*:refs/remotes/<name of remote>/*. In some cases, configuration may be set up to fetch only one branch (specific branch name used instead of wildcard). It should be safe to change the configuration; this will allow fetching all branches.
  • If the branch doesn't exist yet in the remote repository, you can set up the association while pushing it for the first time: git push -u origin develop(that takes care of what you're trying to do with your command at the same time as it pushes the branch)
  • 如果该分支develop已存在于远程存储库中,请用于git fetch更新您的“远程跟踪分支”(本地镜像)。
    • 这需要正确设置 fetch refspec(在.git/config远程部分中);默认为fetch = +refs/heads/*:refs/remotes/<name of remote>/*. 在某些情况下,配置可能会设置为仅获取一个分支(使用特定的分支名称而不是通配符)。更改配置应该是安全的;这将允许获取所有分支。
  • 如果远程存储库中尚不存在该分支,您可以在第一次推送它时设置关联:(git push -u origin develop这会在推送命令的同时处理您尝试对命令执行的操作分支)