使用 git 获取特定分支

use*_*508 19 git github

我想使用 git从master-next 分支下载源代码,如Xilinx wiki 中所述

我试过这个:

#git clone git://github.com/Xilinx/u-boot-xlnx/tree/master-next.git

Initialized empty Git repository in /home/Hannan/master-next/.git/
fatal: remote error:
Xilinx/u-boot-xlnx/tree/master-next is not a valid repository name
Email support@github.com for help
Run Code Online (Sandbox Code Playgroud)

即使这失败了:

# git clone git://github.com/Xilinx/tree/master-next/u-boot-xlnx.git
Initialized empty Git repository in /home/Hannan/u-boot-xlnx/.git/
fatal: remote error:
Xilinx/tree/master-next/u-boot-xlnx is not a valid repository name
Email support@github.com for help
Run Code Online (Sandbox Code Playgroud)

有效的命令是:

 git clone git://github.com/Xilinx/u-boot-xlnx.git
Run Code Online (Sandbox Code Playgroud)

但是我怎么知道这确实会获取master-next 分支而不是master 分支?如何使用 git 正确获取特定分支?

我正在使用 RHEL 6,通过 PuTTY 访问。

Lei*_*iaz 16

就像错误消息告诉您的那样,git clone需要一个 git 存储库。您不能像这样在路径中“添加”分支的名称。查看git 中的分支

您可以克隆单个分支(以及它的历史记录): git clone <url> --branch <branch> --single-branch

git help clone

但是您运行的 clone 命令为您提供了整个存储库的副本,您可以git branch使用git show-branch.

切换到你想要的分支git checkout branch-name

Pro Git书籍(可在线获取)的第一章提供了有关基本命令的更多详细信息。


小智 13

此命令应该有效:

$ git fetch origin [branch]
Run Code Online (Sandbox Code Playgroud)

上面的命令只从远程存储库中获取元数据,它不合并源。

如果要获取和合并源,命令将是:

$ git pull origin [branch]
Run Code Online (Sandbox Code Playgroud)

小心执行合并命令的分支。这将是源合并的地方。