git 获取分支的副本

发布于 2024-11-27 01:50:15 字数 127 浏览 1 评论 0原文

如何从远程 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

东走西顾 2024-12-04 01:50:15

您可以在克隆上使用 --branch-b 选项:

git clone -b <name> url

请参阅 man git clone 了解更多详细信息。

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

git clone -b <name> url

See man git clone for further details.

浮生未歇 2024-12-04 01:50:15

当您克隆时,您将获得所有分支和历史记录。

这里有很好的解释:
git 分支、分叉、获取、合并、变基和克隆,什么有什么区别吗?

使用:

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:

git-branch

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

人事已非 2024-12-04 01:50:15
git clone url
git branch branchname
git checkout branchname
git pull origin branchname

我记得这对我有用。不过,可能有更好的方法,我不是 git 专业人士。

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.

毁虫ゝ 2024-12-04 01:50:15

一种方法是创建一个新的存储库,然后单独获取分支:

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

关于 git clone -b 上的另一个答案的警告

Git 总是克隆整个存储库。工作目录中的内容取决于您签出的分支。因此,如果您想要特定分支,请克隆存储库并签出存储库。

git clone -b 是执行此操作的快捷方式。

同样,您不会获得分支的“副本”,而是签出所需分支的整个存储库。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文