1

I thought running git pull --all was pulling the contents of all remote branches to the local repository. Until this morning anyway, when I ran this on my 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.

I don't understand that error, isn't the whole point of specifying --all not to have to specify a branch? What is even more upsetting, is that the same code seem to work just fine on my Linux box:

[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
 ...

I understand that it might be too optimistic to hope for the same program to behave in the same way on different OSs, but I would like to know if I am doing this correctly, or whether this is a version problem, or whether I misunderstood something?

Jonathan H
  • 7,591
  • 5
  • 47
  • 80
  • Related? http://stackoverflow.com/q/4943827/ – fedorqui Jan 20 '16 at 10:34
  • @fedorqui Thanks a lot for that link, but as posted below I think the answer is different here :) – Jonathan H Jan 20 '16 at 10:37
  • Note that `--all` is passed to `git fetch`, where it means "all remotes", not "all branches". This is a good thing since `git pull` is `git fetch` followed by `git merge`, and the `merge` step uses *all* the branch-names you specify (which for most users is quite wrong if there is more than one such branch: this does an "octopus merge"). – torek Jan 20 '16 at 11:15
  • @torek I understand `git fetch --all` fetches all remotes, but I don't get your second point; does `git pull --all` then iterate on each remote, trying to find matching upstreams amongst local branches, and then run a merge with those matching ones? – Jonathan H Jan 20 '16 at 12:17
  • I'm not entirely sure what happens if your `git pull --all` has two or more remotes that have a matching upstream branch. It *should* still merge only the one that is the actual upstream (as per the `remote` part of the current branch's configuration, e.g., `branch.foo.remote`) but I have never tested it. That's not what I was aiming at though. The issue I was thinking about is that `git pull remote br1 br2 br3` causes an octopus merge with the three fetched branches' tip commits. If `pull --all` meant "all branches", that would imply this kind of merge too. – torek Jan 20 '16 at 18:16

1 Answers1

1

Sorry for my previous question, I think I figured out the answer. Apparently I didn't define the upstream for my local branch foo. Running the following made git pull --all run fine on osx:

git branch -u foo origin/foo

For reference, based on this answer, the following command is useful to check the current tracking state of your repo:

git remote show origin
Community
  • 1
  • 1
Jonathan H
  • 7,591
  • 5
  • 47
  • 80