Linux how to use git to check out a separate branch

  

Linux can check out branches under git, but many users don't know that git can check out a single branch. The method of checking out branches using git does not apply to separate branches. Check out, how does Linux git check out a single branch?

Sometimes, just want to clone a separate branch to (for example, the site posted the code) from the repository, other branches do not need to check out.

At this point, using git clone directly out of the entire repository is not appropriate.

git clone "url" --branch "branch" --single-branch ["folder"]

But this is slightly different from my actual situation, my code was used before Svn managed, has been published on the server using the svn method, using this command prompts an error:

git clone -b qinghaihu --single-branch .

Because there is already a corresponding file on the current directory, there is no such problem if it is published to a new directory.

Another answer:

Clone a specific Git branch [duplicate]

ie:

cd $BRANCH

git init< Br>

git remote add -t $BRANCH -f origin $REMOTE_REPO

git checkout -f $BRANCH

Note that the last checkout command adds a -f parameter so that Forcing an existing file to be overwritten

The above is a description of how git checks out a separate branch. If you use git to check out the entire repository, you will get an error message. You should use the correct command to check out the individual branch.

Copyright © Windows knowledge All Rights Reserved