Search code examples
gitgit-checkoutgit-fetch

List all branches with `git branch -a` does not show recently fetched branch?


I have this history in the console:

Resolving deltas: 100% (58156/58156), completed with 1585 local objects.
From bitbucket.org:interos/datavana
 * branch                datavana.dev.py.3.7.3 -> FETCH_HEAD

$ git checkout datavana.dev.py.3.7.3
error: pathspec 'datavana.dev.py.3.7.3' did not match any file(s) known to git

$ git branch
* alex/dockerize
  master

$ git branch -a
* alex/dockerize
  master
  remotes/origin/HEAD -> origin/master
  remotes/origin/master

I noticed a problem when I tried running:

git checkout datavana.dev.py.3.7.3

because as you can see that didn't work, and this branch is also not listed using git branch -a, anybody know why I can't checkout this branch?


Solution

  • If you take a look the top of your question, you see:

    * branch                datavana.dev.py.3.7.3 -> FETCH_HEAD
    

    This means that the remote reference datavana.dev.py.3.7.3 has been stored locally in FETCH_HEAD. It did not create a local branch with the same name.

    You can create a local branch named datavana.dev.py.3.7.3 by running:

    git checkout -b datavana.dev.py.3.7.3 FETCH_HEAD
    

    You probably ran git fetch <remote> datavana.dev.py.3.7.3, in which case what you see is the expected behavior. From the git-fetch man page:

    The names of refs that are fetched, together with the object names they point at, are written to .git/FETCH_HEAD. This information may be used by scripts or other git commands, such as git-pull(1).

    You would normally check out a remote branch using git checkout.