git get a copy of a branch [closed]
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.
精彩评论