开发者

git get a copy of a branch [closed]

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center. Closed 10 years ago.

how do I get a 开发者_如何学JAVAcopy of a branch from a remote git server? I have tried the following options

git clone url
git clone url branchName  

it looks they get the master copy.


You can use the the --branch or -b option on clone:

git clone -b <name> url

See man git clone for further details.


when you clone you get ALL the branches and history.

good explanation here: git branch, fork, fetch, merge, rebase and clone, what are the differences?

use:

git-branch

once you clone the repository to see the branches in the repository.


git clone url
git branch branchname
git checkout branchname
git pull origin branchname

this works for me afa i remember. there might be some better way though, i'm not a git pro.


One way is to create a new repo and then fetch the branch alone:

git init .
git fetch <url> <branchname>:refs/remotes/origin/<branchname>
git checkout <branchname>

Caveat about the other answer on git clone -b

Git always clones the entire repository. What you have in your working directory is based on which branch you checkout. So if you want a particular branch, clone the repo and checkout the repo.

git clone -b is the shortcut for doing that.

Again, you are not getting a "copy" of your branch, but the whole repo with the required branch checked out.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜