How to Clone Remote Branches

Since cloning is very important process in Git, in this tutorial, we will c how to clone branches from the remote repository.

  • Firstly, clone the remote repository and cd into it.
    git clone git://
    cd example project
  • Secondly, list the local branches using the git branch command for listing the branches and git branch with the -a option for listing all remote branches:
    git branch // Lists local branches
    git branch -a // Lists local and all remote branches
  • Then, check out the remote branch locally. If the name of the remote branch and the one of the checked out branch turns out the same, it will automatically track the remote branch.
    git checkout <branch>
  • Now let’s fetch the remote master branch:
    git clone
    cd example
    git checkout master

Concept of Cloning

Cloning is to download the complete source code to the local machine. When cloning a repository, all the files are downloaded to the local system not affecting the remote Git Repository. The git clone command clones and copies of an existing repository into a new directory. It is also used to create remote-tracking branches for each branch in the cloned repository. It also allows users to get a development copy of an existing central repository.

Remote Branches

The git branch command creates, lists and deletes branches. It not only operates on the local branches but also remote branches. Remote branches are pointers to the state of branches in the remote repositories. These branches are local and they cannot move unless you operate. Remote branches are reminders of where the branches on the remote repositories were the last time you worked on them.

Do you find this helpful?

Related articles