1、 使用 git clone 命令时,通过 -b 参数指定要拉取的分支:
bash
git clone -b <branch-name> --single-branch <repository-url>
-b <branch-name>:指定你想要克隆的分支名称。--single-branch:告诉Git只克隆指定的分支。<repository-url>:仓库的URL地址。
示例
如果你想克隆GitHub上某个仓库的feature-branch分支,命令将类似于:
bash
git clone -b feature-branch --single-branch https://github.com/username/repository.git
这条命令会克隆远程仓库中的feature-branch分支到本地,并且只包含这个分支的内容。