wtmatter.com Open in urlscan Pro
2606:4700:3035::ac43:8f39  Public Scan

URL: https://wtmatter.com/git-branch-clone/
Submission: On October 21 via api from US — Scanned from DE

Form analysis 4 forms found in the DOM

POST #

<form action="#" method="post" accept-charset="utf-8" id="subscribe-blog-547">
  <div id="subscribe-text">
    <p>Receive updates of our latest articles via email. Enter your email address below to get started.</p>
  </div>
  <p id="subscribe-email">
    <label id="jetpack-subscribe-label" class="screen-reader-text" for="subscribe-field-547"> Email Address </label>
    <input type="email" name="email" required="required" value="" id="subscribe-field-547" placeholder="Email Address">
  </p>
  <p id="subscribe-submit">
    <input type="hidden" name="action" value="subscribe">
    <input type="hidden" name="source" value="https://wtmatter.com/git-branch-clone/">
    <input type="hidden" name="sub-type" value="widget">
    <input type="hidden" name="redirect_fragment" value="547">
    <button type="submit" style="margin-left: 0px;" name="jetpack_subscriptions_widget"> Sign Me Up </button>
  </p>
</form>

POST https://wtmatter.com/wp-comments-post.php

<form action="https://wtmatter.com/wp-comments-post.php" method="post" id="commentform" class="comment-form" novalidate="">
  <p class="comment-notes"><span id="email-notes">Your email address will not be published.</span> Required fields are marked <span class="required">*</span></p>
  <p class="comment-form-comment"><label for="comment">Comment</label> <textarea id="comment" name="comment" cols="45" rows="8" maxlength="65525" required="required"></textarea></p>
  <p class="comment-form-author"><label for="author">Name <span class="required">*</span></label> <input id="author" name="author" type="text" value="" size="30" maxlength="245" required="required"></p>
  <p class="comment-form-email"><label for="email">Email <span class="required">*</span></label> <input id="email" name="email" type="email" value="" size="30" maxlength="100" aria-describedby="email-notes" required="required"></p>
  <p class="comment-form-url"><label for="url">Website</label> <input id="url" name="url" type="url" value="" size="30" maxlength="200"></p>
  <p class="comment-form-cookies-consent"><input id="wp-comment-cookies-consent" name="wp-comment-cookies-consent" type="checkbox" value="yes"> <label for="wp-comment-cookies-consent">Save my name, email, and website in this browser for the next time
      I comment.</label></p>
  <p class="comment-subscription-form"><input type="checkbox" name="subscribe_comments" id="subscribe_comments" value="subscribe" style="width: auto; -moz-appearance: checkbox; -webkit-appearance: checkbox;"> <label class="subscribe-label"
      id="subscribe-label" for="subscribe_comments">Notify me of follow-up comments by email.</label></p>
  <p class="comment-subscription-form"><input type="checkbox" name="subscribe_blog" id="subscribe_blog" value="subscribe" style="width: auto; -moz-appearance: checkbox; -webkit-appearance: checkbox;"> <label class="subscribe-label"
      id="subscribe-blog-label" for="subscribe_blog">Notify me of new posts by email.</label></p>
  <p class="form-submit"><input name="submit" type="submit" id="submit" class="submit" value="Post Comment"> <input type="hidden" name="comment_post_ID" value="3565" id="comment_post_ID">
    <input type="hidden" name="comment_parent" id="comment_parent" value="0">
  </p>
</form>

GET https://wtmatter.com/

<form method="get" class="searchform" action="https://wtmatter.com/" role="search">
  <div class="flex-row relative">
    <div class="flex-col flex-grow">
      <input type="search" class="search-field mb-0" name="s" value="" id="s" placeholder="Search…" autocomplete="off">
    </div>
    <div class="flex-col">
      <button type="submit" class="ux-search-submit submit-button secondary button icon mb-0" aria-label="Submit">
        <i class="icon-search"></i> </button>
    </div>
  </div>
  <div class="live-search-results text-left z-top">
    <div class="autocomplete-suggestions" style="position: absolute; display: none; max-height: 300px; z-index: 9999;"></div>
  </div>
</form>

GET https://wtmatter.com/

<form method="get" class="searchform" action="https://wtmatter.com/" role="search">
  <div class="flex-row relative">
    <div class="flex-col flex-grow">
      <input type="search" class="search-field mb-0" name="s" value="" id="s" placeholder="Search…" autocomplete="off">
    </div>
    <div class="flex-col">
      <button type="submit" class="ux-search-submit submit-button secondary button icon mb-0" aria-label="Submit">
        <i class="icon-search"></i> </button>
    </div>
  </div>
  <div class="live-search-results text-left z-top">
    <div class="autocomplete-suggestions" style="position: absolute; display: none; max-height: 300px; z-index: 9999;"></div>
  </div>
</form>

Text Content

Skip to content
 * 


 * Blog
 * Services
   * Development
   * Consultancy
   * Digital Marketing & SEO
   * Graphics & Video
 * Portfolio
 * Tools
 * Contact Us





PROGRAMMING, SOFTWARE AND TOOLS


CLONING A SPECIFIC GIT BRANCH


Posted on January 9, 2020January 9, 2020 by Gurmeet Singh
09
Jan

This is a detailed tutorial on cloning a specific git branch. Learn to duplicate
a single branch with git without any additional data from other branches.

Table of Contents

 * How To Clone A Specific Git Branch?
 * Cloning repository and Checking out to a particular branch


HOW TO CLONE A SPECIFIC GIT BRANCH?

Sometimes, you might be wanted to clone just a single and particular git branch.
The default git clone command with --branch the option will actually clone the
complete git repository and will check out to the specific branch whose name is
followed by the --branch option. But the thing here is we do not want to even
the data of any other branch. The purpose here is to just clone a very specific
git branch and only the data associated with that specific branch.

The following command will solve this purpose. This command will only fetch the
branch whose name is mentioned in the command ignoring all other branches and
their data.


Python

git clone --single-branch --branch <branchname> <remote-repo-url>
1
git clone --single-branch --branch <branchname> <remote-repo-url>

The option --single-branch does the job of selecting the specific branch but
make sure that you can make use of this option in git version 1.7.10 and above.

Example. The following git command clones only the branch named revert-28-master
from the git URL https://github.com/abhat222/Data-Science--Cheat-Sheet.git


Python

git clone --single-branch --branch revert-28-master
https://github.com/abhat222/Data-Science--Cheat-Sheet.git
1
git clone --single-branch --branch revert-28-master
https://github.com/abhat222/Data-Science--Cheat-Sheet.git



For the older versions of git, you can use the following command(s) for the same
purpose of cloning only a particular branch.


Python

git init git remote add -t <branchname> -f origin <remote-repo-url> git checkout
<branchname>
1
2
3
git init
git remote add -t <branchname> -f origin <remote-repo-url>
git checkout <branchname>

Example. An example using the above set of commands to clone a specific git
branch, the branch master from another git repository URL.


Python

git remote add -t master -f origin https://github.com/google/eng-practices.git
1
git remote add -t master -f origin https://github.com/google/eng-practices.git




CLONING REPOSITORY AND CHECKING OUT TO A PARTICULAR BRANCH

You can also clone the entire repository and can checkout to a particular branch
directly with a single command. In case, just use the following git command.


Python

git clone --branch <branchname> <remote-repo-url>
1
git clone --branch <branchname> <remote-repo-url>

The difference is just not using the option --single-branch.

Note. Cloning the entire repository and then checking out to a particular branch
is not a good idea in case if you just want to work with that specific
particular branch and have nothing to do with the rest of the branches and their
data on the repository. But it’s a good idea in the case, for now, you just want
to checkout to a particular branch but later may require to switch to other
branches.



Example. The following command illustrates the use of the git clone command to
clone the entire repository and then checking out to pdmack-patch-1 branch.


Python

git clone --branch pdmack-patch-1 https://github.com/kubeflow/kubeflow.git
1
git clone --branch pdmack-patch-1 https://github.com/kubeflow/kubeflow.git

An example of the above command usage is shown in the screenshot given below.



Related Articles.

 * Rename Git Branch – Locally &  Remotely
 * Git Set UpStream – What Does It Do & How To Use It?
 * Git Commands Explained With Examples

I hope you found this guide useful. Do share it with others who might find it
useful as well. If you have any questions related to this article, feel free to
ask us in the comments section.

And do not forget to subscribe to WTMatter!


SUBSCRIBE TO WTMATTER!

Receive updates of our latest articles via email. Enter your email address below
to get started.

Email Address

Sign Me Up





RELATED POSTS:

 * Rename Git Branch - Locally & Remotely



This entry was posted in Programming, Software and Tools and tagged git, git
branch, Git Commands, github.

GURMEET SINGH

I am an IT Engineer, doing lots of stuff like Web Development, Machine Learning,
Digital Marketing, Consultation, Blogging and more. I share useful technical
stuff here at WTMatter regularly. Find out more about me in the About page.

Python zip() function for Mapping (Tutorial)
Python enumerate() Tutorial



LEAVE A REPLY CANCEL REPLY

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

Comment

Name *

Email *

Website

Save my name, email, and website in this browser for the next time I comment.

Notify me of follow-up comments by email.

Notify me of new posts by email.



Categories

 * Affiliate Marketing
 * Blogging
 * Computing
 * Content Writing
 * DBMS
 * Deals
 * Digital Marketing
 * Email Marketing
 * Java
 * Javascript
 * Linux
 * Miscellaneous
 * Networking
 * PHP
 * Programming
 * Python
 * Search Engine Marketing
 * Search Engine Optimization
 * Social Media Marketing
 * Software and Tools
 * SQL
 * Web Designing
 * Web Development
 * Web Hosting
 * WordPress

Latest Posts

 * Difference – NumPy uFuncs (Python Tutorial)
 * Products – NumPy uFuncs (Python Tutorial)
 * Summations – NumPy uFuncs (Python Tutorial)
 * NumPy Logs – NumPy uFuncs (Python Tutorial)
 * Rounding Decimals – NumPy uFuncs (Python Tutorial)


 * Home
 * Blog
 * About Us
 * Contact Us


QUICK LINKS

 * Development
 * Consultancy
 * Digital Marketing & SEO
 * Portfolio
 * Tools


CONTACT INFORMATION

 Email Address
admin@wtmatter.com


FOLLOW US


Copyright 2021 © WTMatter | An Initiative By Gurmeet Singh
 * 
 * Blog
 * Services
   * Development
   * Consultancy
   * Digital Marketing & SEO
   * Graphics & Video
 * Portfolio
 * Tools
 * Contact Us
 *