Git pull——在osx/linux上的行为都不同

Git pull——在osx/linux上的行为都不同,linux,git,macos,Linux,Git,Macos,我认为运行git pull--all就是将所有远程分支的内容拉到本地存储库。直到今天早上,当我在我的MacBook上运行时: [me@macbox folder]> git --version git version 1.9.3 (Apple Git-50) [me@macbox folder]> git branch * foo master [me@macbox folder]> git remote -v origin git@gitserver:me/myrepo

我认为运行
git pull--all
就是将所有远程分支的内容拉到本地存储库。直到今天早上,当我在我的MacBook上运行时:

[me@macbox folder]> git --version
git version 1.9.3 (Apple Git-50)
[me@macbox folder]> git branch
* foo
  master
[me@macbox folder]> git remote -v
origin  git@gitserver:me/myrepo.git (fetch)
origin  git@gitserver:me/myrepo.git (push)
[me@macbox folder]> git pull --all
Fetching origin
You asked to pull from the remote '--all', but did not specify
a branch. Because this is not the default configured remote
for your current branch, you must specify a branch on the command line.
[me@macbox folder]> git checkout master
Switched to branch 'master'
Your branch is up-to-date with 'origin/master'.
[me@macbox folder]> git pull --all
Fetching origin
Already up-to-date.
我不理解这个错误,指定
--all
的目的不就是不必指定一个分支吗?更令人不安的是,同样的代码似乎在我的Linux机器上运行得很好:

[me@linuxbox folder]> git --version
git version 1.7.1
[me@linuxbox folder]> git branch
* master
[me@linuxbox folder]> git remote -v
origin  git@gitserver:me/myrepo.git (fetch)
origin  git@gitserver:me/myrepo.git (push)
[me@linuxbox folder]> git pull --all
Fetching origin
remote: Counting objects: 164, done.
remote: Compressing objects: 100% (138/138), done.
remote: Total 164 (delta 114), reused 36 (delta 23)
Receiving objects: 100% (164/164), 33.63 KiB, done.
Resolving deltas: 100% (114/114), completed with 30 local objects.
From gitserver:me/myrepo
 * [new branch]      foo        -> origin/foo
   b4b1efe..4e5f299  master     -> origin/master
Updating 9fd42cb..4e5f299
Checking out files: 100% (15/15), done.
Fast-forward
 ...

我明白,希望同一个程序在不同的操作系统上以同样的方式运行可能过于乐观,但我想知道我这样做是否正确,或者这是版本问题,还是我误解了什么?

对不起,我想我已经找到了答案。显然,我没有为我的本地分支
foo
定义上游。在osx上运行以下命令可以使git pull--all正常运行:

git branch -u foo origin/foo
以下命令可用于检查回购的当前跟踪状态,以供参考:

git remote show origin

相关的@fedorqui非常感谢这个链接,但正如下面所发布的,我认为这里的答案是不同的:)注意,
--all
被传递到
git fetch
,这里的意思是“所有远程”,而不是“所有分支”。这是一件好事,因为
git pull
git fetch
,然后是
git merge
,并且
merge
步骤使用您指定的所有分支名称(对于大多数用户来说,如果有多个这样的分支,这是非常错误的:这是一个“八达通合并”)@torek我理解git fetch--all获取所有遥控器,但我不明白你的第二点;
git pull--all
是否会在每个远程上迭代,试图在本地分支之间找到匹配的上游,然后与那些匹配的分支运行合并?如果您的
git pull--all
有两个或多个具有匹配上游分支的远程,我不完全确定会发生什么。它仍然应该只合并实际上游的一个(根据当前分支配置的
remote
部分,例如
branch.foo.remote
),但我从未测试过它。但这不是我的目标。我考虑的问题是,
git pull remote br1 br2 br3
会导致八达通合并三个获取分支的提示提交。如果
pull--all
表示“所有分支”,那么也意味着这种合并。