When I cloned a remote repository, I used the following command-
git clone -b mybranch --single-branch git://sub.domain.com/repo.git
After that, when I did a git branch -l
it just showed me the branch I cloned. Now, I want a pull of another branch, but it is not showing me other branches. What should I do?
You can list the branches directly on the remote with git ls-remote
command:
git ls-remote git://sub.domain.com/repo.git
Then use git fetch
command to fetch a specific branch and git checkout
command to switch to the branch.
git branch -l
shows you local branches. You want remote branches, so try git branch -r
. When you see the branch you want, you can automatically create and checkout a local branch tracking the given remote branch with git checkout <remote branch name>
.
For example, if your git branch -r
shows a branch you want called origin/my-feature
, just do
$ git checkout my-feature
Note that:
git branch --list
, by default, lists local branches, not remote ones (git branch -r
): you can create local branches after those remote ones in order to "see other branches".git branch -l
only lists local branches as a side-effect:
It is not the same as git branch --list
, and '-l
' will be deprecated with Git 2.19 (Q3 2019).
The "-l
" option in "git branch -l
" is an unfortunate short-hand for
"--create-reflog
", but many users, both old and new, somehow expect
it to be something else, perhaps "--list
".
This step warns when "-l
" is used as a short-hand for "--create-reflog
" and warns about the future repurposing of the it when it is used.
See commit 055930b, commit 7687f19, commit 6b15595 (22 Jun 2018) by Jeff King (peff
).
(Merged by Junio C Hamano -- gitster
-- in commit d18602f, 18 Jul 2018)
branch
: deprecate "-l
" optionThe "
-l
" option is short for "--create-reflog
". This has caused much confusion over the years.
Most people expect it to work as "--list
", because that would match the other "mode" options like-d
/--delete
and-m
/--move
, as well as the similar-l
/--list
option ofgit-tag
.Adding to the confusion, using "
-l
" appears to work as "--list
" in some cases:$ git branch -l * master
because the branch command defaults to listing (so even trying to specify
--list
in the command above is redundant).
But that may bite the user later when they add a pattern, like:$ git branch -l foo
which does not return an empty list, but in fact creates a new branch (with a reflog, naturally) called "foo".
It's also probably quite uncommon for people to actually use "
-l
" to create a reflog. Since 0bee591 (Enable reflogs by default in any repository with a working directory., 2006-12-14 Git v1.5.0), this is the default in non-bare repositories.
So it's rather unfortunate that the feature squats on the short-and-sweet "-l
" (which was only added in 3a4b3f2 (Create/delete branch ref logs., 2006-05-19, Git v1.4.0), meaning there were only 7 months where it was actually useful).Let's deprecate "
-l
" in hopes of eventually re-purposing it to "--list
".
With Git 2.20 (Q2 2018), -l
is officially short for --list
.
See commit 94a1380 (30 Aug 2018), and commit a15d598 (22 Jun 2018) by Jeff King (peff
).
(Merged by Junio C Hamano -- gitster
-- in commit 7dc341c, 17 Sep 2018)
来源:https://stackoverflow.com/questions/17514489/change-the-branch-when-the-branch-not-shown-in-git-branch-l