2

Let us consider two following cases.

Case #1 (shallow clone).

$ git clone --depth 5 ssh://{REMOTE_URL}/project.git
...
$ git checkout fd459887439f2cf93725c2f4a1a39997e865a86d // it is just a latest commit (took it from "git rev-parse HEAD")
...
$ git branch
* (detached from fd45988)
  master

$ git pull
Already up-to-date.

Case #2 (clone without --depth).

$ git clone ssh://{REMOTE_URL}/project.git
...
$ git checkout fd459887439f2cf93725c2f4a1a39997e865a86d // it is just a latest commit (took it from "git rev-parse HEAD")
...
$ git branch
* (detached from fd45988)
  master

$ git pull
You are not currently on a branch. Please specify which
branch you want to merge with. See git-pull(1) for details.

    git pull <remote> <branch>

So, the difference is only that in the first case I clone limited number of commits and in the second case I clone all commits. The branch is the same in both cases as shows "git branch" output.

Question: why "pull" does work in the first case and does not work in the second case?

Alexander Samoylov
  • 2,358
  • 2
  • 25
  • 28
  • Try repeating without using pull, but with fetch and merge instead? – evolutionxbox Nov 09 '18 at 10:50
  • Yes, if I try Case #2 as "git fetch; git merge origin/master" then it works. It means that somehow git does not know the branch in the Case #1. I am just curious, why... – Alexander Samoylov Nov 09 '18 at 11:22
  • Why merge origin/master? I think the reason is that a detached head has no tracking info so git doesn’t know what to merge. In the shallow example git likely doesn’t merge anything. – evolutionxbox Nov 09 '18 at 11:24

0 Answers0