Remote branch not visible in local repo

Viewed 402

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?

1 Answers

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 to

git switch -c <branch> --track <remote>/<branch>
Related