【问题标题】:Git branches: tracking upstreamGit 分支:跟踪上游
【发布时间】:2012-12-14 20:49:13
【问题描述】:

我不知道我是在误用 ​​Git,还是我遇到了配置问题。

我将我的 Github 存储库克隆到机器 A 和 B 上,然后在机器 A 上克隆:

git checkout -b branchA
// make edits
git add .
git commit -am "initial"
git push

然后在机器 B 上做:

git pull
git checkout branchA
// make edits
git commit -am "edits"
git push

然后在机器 A 上做:

git pull

但是它说:

There is no tracking information for the current branch

所以我必须这样做:

git branch --set-upstream branchA origin/branchA

为什么我必须设置上游,当它最初推送到 origin/branchA 时没有问题?

我正在使用 msygit 1.8。在 Windows 上。

附:当我在机器 B 上执行 pull 时,为什么默认不跟踪新分支 branchAgit branch 没有显示它(但它与 -r 一起显示)。当我pull?时,我可以默认跟踪所有新的远程分支吗?

【问题讨论】:

  • 您的存储库中git config push.default 的输出是什么?不会是current,对吗?
  • 它不返回任何东西(在机器 A 上):/

标签: git


【解决方案1】:

因为git config push.default 不返回任何内容,这意味着,对于“git 1.8.0.msysgit.0”,您的git push 表示git push origin :,参考规范“:”代表“匹配”分支。

这里它在远程端创建一个匹配的branchA

但这并不能使它成为一个远程跟踪分支。
换句话说,branch.branchA.merge 没有设置任何内容。
这就是 git pull 失败的原因:它不知道应该合并到本地 branchA 的远程分支。


注意,您的第一个 git push 应该显示以下消息:

warning: push.default is unset; its implicit value is changing in
Git 2.0 from 'matching' to 'simple'. To squelch this message
and maintain the current behavior after the default changes, use:

  git config --global push.default matching

To squelch this message and adopt the new behavior now, use:

  git config --global push.default simple

See 'git help config' and search for 'push.default' for further information.
(the 'simple' mode was introduced in Git 1.7.11. Use the similar mode
'current' instead of 'simple' if you sometimes use older versions of Git)

因此,使用 Git2.0,git push 将失败。
推送branchA 的唯一方法是显式设置其上游分支(使用相同的名称):

git push -u origin branchA

【讨论】:

  • 有道理,谢谢。那么是否有一个配置设置来防止这种行为(即让git push/git push origin : 创建一个远程跟踪分支?)还是我总是必须push -u
  • @AndrewBullock 您应该使用-u 进行第一次推送。在那之后,你就不需要它了。还将默认推送模式设置为简单的帮助强制执行本地分支和远程跟踪分支之间的对应关系。
  • @AndrewBullock 说,上游模式可以在这里帮助你,如果你不想明确使用-u:见stackoverflow.com/a/13751847/6309
猜你喜欢
  • 2020-09-26
  • 2023-01-14
  • 2011-06-24
  • 2012-03-03
  • 2014-02-04
  • 2016-08-09
  • 2014-08-22
  • 2018-12-11
相关资源
最近更新 更多