如何从远程git服务器获取分支的副本?我尝试了以下选项
git clone url
git clone url branchName
看起来他们得到了主副本。
答案 0 :(得分:5)
您可以在克隆上使用--branch
或-b
选项:
git clone -b <name> url
有关详细信息,请参阅man git clone
。
答案 1 :(得分:1)
当您克隆时,您将获得所有分支和历史记录。
这里有很好的解释: git branch, fork, fetch, merge, rebase and clone, what are the differences?
使用:
git-branch
克隆存储库以查看存储库中的分支。
答案 2 :(得分:0)
git clone url
git branch branchname
git checkout branchname
git pull origin branchname
这对我有用,我记得。可能有一些更好的方法,我不是一个git pro。
答案 3 :(得分:0)
一种方法是创建一个新的repo然后单独获取分支:
git init .
git fetch <url> <branchname>:refs/remotes/origin/<branchname>
git checkout <branchname>
警告git clone -b
Git 总是克隆整个存储库。您工作目录中的内容取决于您签出的分支。因此,如果您需要特定分支,请克隆仓库并签出仓库。
git clone -b
是执行此操作的快捷方式。
同样,你没有获得你的分支的“副本”,但检查了所需分支的整个仓库。