in Technology by
How to clone all remote branches in Git?

1 Answer

0 votes
by
$ git clone git://example.com/myproject
$ cd myproject

Next, look at the local branches in your repository:

$ git branch
* master

But there are other branches hiding in your repository! You can see these using the -a flag:

$ git branch -a
* master
  remotes/origin/HEAD
  remotes/origin/master
  remotes/origin/v1.0-stable
  remotes/origin/experimental

If you just want to take a quick peek at an upstream branch, you can check it out directly:

$ git checkout origin/experimental

But if you want to work on that branch, you'll need to create a local tracking branch which is done automatically by:

$ git checkout experimental

and you will see

Branch experimental set up to track remote branch experimental from origin.
Switched to a new branch 'experimental'

Here, "new branch" simply means that the branch is taken from the index and created locally for you. As the previous line tells you, the branch is being set up to track the remote branch, which usually means the origin/branch_name branch.

Now, if you look at your local branches, this is what you'll see:

$ git branch
* experimental
  master

You can actually track more than one remote repository using git remote.

$ git remote add win32 git://example.com/users/joe/myproject-win32-port
$ git branch -a
* master
  remotes/origin/HEAD
  remotes/origin/master
  remotes/origin/v1.0-stable
  remotes/origin/experimental
  remotes/win32/master
  remotes/win32/new-widgets

At this point, things are getting pretty crazy, so run gitk to see what's going on:

$ gitk --all &

Related questions

0 votes
    What is the difference between ‘git remote’ and ‘git clone’?...
asked Nov 2, 2020 in Technology by JackTerrance
0 votes
    I cloned a Git repository, which contains about five branches. However, when I do git branch I only see one of ... staging * etc... Select the correct answer from above options...
asked Feb 4, 2022 in Education by JackTerrance
0 votes
    How can we clone a Git repository into a specific folder?...
asked Jan 8, 2021 in Technology by JackTerrance
0 votes
    What is the use of git clone command?...
asked Nov 4, 2020 in Technology by JackTerrance
0 votes
    How can we see the differences between the two branches in Git?...
asked Jan 8, 2021 in Technology by JackTerrance
0 votes
    I am trying to create a "feature branch" from golang. The following code is not working: reader : ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 9, 2022 in Education by JackTerrance
0 votes
    How to rename and remove branch in remote Git?...
asked Aug 24, 2021 in Technology by JackTerrance
0 votes
    How can we create a remote Git branch?...
asked Jan 8, 2021 in Technology by JackTerrance
0 votes
    Explain How to change the URI (URL) for a remote Git repository?...
asked Jan 7, 2021 in Technology by JackTerrance
0 votes
    How to push a new local branch to a remote Git repository and track it too?...
asked Jan 7, 2021 in Technology by JackTerrance
0 votes
    How can we check out a remote Git branch?...
asked Jan 7, 2021 in Technology by JackTerrance
0 votes
    I created a local branch that I want to 'push' upstream. There is a similar question here on Stack ... the upstream repository? Select the correct answer from above options...
asked Feb 2, 2022 in Education by JackTerrance
0 votes
    How do you delete a Git tag that has already been pushed? Select the correct answer from above options...
asked Feb 2, 2022 in Education by JackTerrance
0 votes
    I pulled a project from GitHub a few days ago. I've since discovered that there are several forks on GitHub, ... those forks I pulled? Select the correct answer from above options...
asked Feb 2, 2022 in Education by JackTerrance
0 votes
    we are using git in Team Foundation Service, and we are trying to find a way to delete a remote ... /DefaultCollection/_git/Xxxxxx' Select the correct answer from above options...
asked Feb 1, 2022 in Education by JackTerrance
...