I have a remote Git (Github) repo. I cloned it using the git clone
command. but when I try to see the branches Using the git branch
command it only shows one branch, 'main',while there is at least 15+ branches on the remote repo, which are visible via the command git branch -r
. How can I get my all the remote branches into my local repo?
Asked
Active
Viewed 1,047 times
4

Raedwald
- 46,613
- 43
- 151
- 237

Pranay kumar
- 1,983
- 4
- 22
- 51
-
3If you can see them with `git branch -a` (or `-r`) then they exist in your local repository. You can reference them by their full name, e.g. `origin/somebranch`. If you want to switch to a remote branch, use `git switch branchname` (without `origin/`) – Jan Wilamowski Aug 23 '21 at 05:49
-
https://stackoverflow.com/a/72156/7976758 Found in https://stackoverflow.com/search?q=%5Bgit%5D+clone+all+branches – phd Aug 23 '21 at 08:58
1 Answers
5
The idea is to not "pollute" your local branch namespace with all the remote tracking branches.
Using git branch -avv
, you will see both local (main) and remote tracking branches (origin/xxx
).
You can use the "guess mode" of git switch
to create a local branch which will have its corresponding remote branch as upstream.
git switch <branch>
If
<branch>
is not found, but there does exist a tracking branch in exactly one remote (call it<remote>
) with a matching name, treat as equivalent togit switch -c <branch> --track <remote>/<branch>

VonC
- 1,262,500
- 529
- 4,410
- 5,250