简体   繁体   中英

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?

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 .

why did it do the FETCH_HEAD thing, never seen that before?
I just ran git fetch

Then double-check your git config remote.origin.fetch setting:
A default refspec should have created the local branch for you on fetch:

+refs/heads/*:refs/remotes/origin/*

But if you have a different refspec, then the remote branch is fetched, and its reference is stored in FETCH_HEAD

A git fetch datavana.dev.py.3.7.3:datavana.dev.py.3.7.3 would also have created the branch locally.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM