Git checks out a separate branch example

Source: Internet
Author: User
Tags svn git clone

Sometimes you just want to clone a separate branch from the repository (for example, the code published by the Web site), and other related branches do not need to be checked out.

It is not appropriate to use GIT to clone the entire version library directly. Search for a bit, found that the need for a lot of stackoverflow on a number of relevant answers:

How to clones a single branch in Git?

In this question, the answer to the most acceptable is this:

git clone <url>--branch <branch>--single-branch [<folder>]

But this answer is slightly different from my actual situation, my code was previously managed with SVN, on the server has been published using the SVN method, using this command prompted the error:

Git clone-b qinghaihu--single-branch.

Because the current directory already has a corresponding file, if published to a new directory is not the problem.

Find the answer from another question:

Clone a specific Git branch [duplicate]

That

CD $BRANCH
Git init
git remote add-t $BRANCH-F Origin $REMOTE _repo
Git checkout-f $BRANCH

Note that the last checkout command adds a-f argument so that you can force overwriting an existing file

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.