How To Clone A GIT Branch-GIT Clone Specific Branch-DecodingDevOps

How To Clone A GIT Branch-GIT Clone Specific Branch-DecodingDevOps

Git Clone Specific Branch:

When you are working in a project, you have to work on only specific branches we don't need to clone entire git repository. So at that time we have to clone a specific branch from git repository. If you clone the entire repository it will occupy more space in your system, So cloning only the particular branch will be useful to save some space in your system. In the following steps i will show you how to clone a git branch step by step

Git clone branch command

by using below command you can clone only specific branch in your git or bit-bucket  repository.

git clone <Cloning_URL> -b <branch_name>

in the place of <Cloning_URL> write your cloning URL of your git or bit bucket repository and in the place of <branch_name> mention your branch name which you want to clone.

Ex:

git clone https://github.com/decodingdevops/decodingdevops.git -b vijay

here i am cloning vijay branch from my repository.

long-winded way:

mkdir abcd
cd abcd
git init
git remote add -t <branch_name> origin <cloning_url>
git pull
git checkout <branch_name>

What this does is:

here we are creating a directory called abcd. you can name as it your wish and we are going to create an empty git repository in this directory. and we are adding the original repository as a remote called origin. and we are fetching only the branch we require from the remote called origin. after doing git pull you have to checkout to your required branch and there you can see only files of that branch which you cloned.

  • how to clone a git branch
  • clone git branch
  • how to clone specific branch in git

Leave a Reply

Your email address will not be published. Required fields are marked *