I have observed that if I have multiple branches in GitHub and if I cloned it locally, by default I see only main branch when I run “git branch -l” I dont see any branch there.
But when I run “git switch <Branch_name>”, it switches to that branch and then if I run command “git branch -l”, I see both the main branch and this branch. so if there are 5 branches in GitHub repository, I need to switch to all branches after cloning the reposotory locally to be able to see all the branches.
Is this normal behavior?
What you probably want is to use git fetch --all
, which will make remote branches available to your local repository. Then you should see those branches locally.
Nope, it doesnt work.
I have a repository in GitHub with 2 branches(main and branch-2)
when I run “git clone ”, it creates the repository folder.
in the repository folder, when I run git branch -l, it just shows main branch.
I ran “git fetch --all” but still the same.
when I run “git switch branch-2” it switches to this branch,
then when I run “git branch -l”, it gives me list of both branches.
when I try to switch to any non-existing branch, it shows error, which is expected.
So basically, untill I switch the branch, it wont show the branch in the list of branches.
did you consider doing git branch -rl
? The -l
version does not list remote branches.