In this article, we will discuss how to clone from a specific branch. Let’s begin!

Git is a distributed version control system designed to track changes to a project. Github is web based hosting service for version control using Git.

Install Git

Windows

Download and install the latest Git for Windows here.

Linux

Debian or Ubuntu

sudo apt-get update
sudo apt-get install git

sudo apt-get install git

Mac

Download and install the latest Git for Mac here.

Now, we have got Git installed. Use the following code to clone the repository.

git clone <repository URL>

When working with git, we will likely have different features. We will have multiple contributor working on the same project. Branching is a main feature in Git helps in managing the workflow of different versions of a project. The master branch is the default branch. Therefore, when you clone a repository, you clone the master and all other branches. Then you can checkout to other branches.

Now let’s see how to clone a specific branch from repository. There are two ways to clone a specific branch.

  • Clone the repository (fetch all branches) and checkout to a specific branch.
  • Clone the repository and fetch only a single branch.
git clone --branch <branch-name> <repository-url>

or

git clone -b <branch-name> <repository-url>

Undergraduate, Computer Science & Engineering

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store