git 获取分支的副本
如何从远程 git 服务器获取分支的副本?我已经尝试了以下选项
git clone url
git clone url branchName
,看起来他们获得了主副本。
how do I get a copy 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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您可以在克隆上使用
--branch
或-b
选项:请参阅
man git clone
了解更多详细信息。You can use the the
--branch
or-b
option on clone:See
man git clone
for further details.当您克隆时,您将获得所有分支和历史记录。
这里有很好的解释:
git 分支、分叉、获取、合并、变基和克隆,什么有什么区别吗?
使用:
来查看存储库中的分支。
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:
once you clone the repository to see the branches in the repository.
我记得这对我有用。不过,可能有更好的方法,我不是 git 专业人士。
this works for me afa i remember. there might be some better way though, i'm not a git pro.
一种方法是创建一个新的存储库,然后单独获取分支:
关于 git clone -b 上的另一个答案的警告
Git 总是克隆整个存储库。工作目录中的内容取决于您签出的分支。因此,如果您想要特定分支,请克隆存储库并签出存储库。
git clone -b 是执行此操作的快捷方式。
同样,您不会获得分支的“副本”,而是签出所需分支的整个存储库。
One way is to create a new repo and then fetch the branch alone:
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.