克隆特定的 Git 分支
本文将讨论通过获取所有分支并签出特定分支来从远程仓库克隆特定 git 分支。
通过获取所有分支并签出到特定分支,从远程仓库克隆特定 Git 分支
我们将克隆一个包含两个分支的远程仓库,即 master
和 gh-pages
,然后切换到 gh-pages
分支。
<!-- The command to use is -->
git clone <remote-repo-url>
<!-- From your terminal run -->
git clone https://github.com/KEVINAMAYI/AkanNameGenerator.git
输出:
Cloning into 'AkanNameGenerator'...
remote: Enumerating objects: 94, done.
remote: Total 94 (delta 0), reused 0 (delta 0), pack-reused 94
Unpacking objects: 100% (94/94), 2.38 MiB | 1.86 MiB/s, done.
我们将进入项目文件夹并使用以下命令列出可用的分支。
<!-- get into project folder -->
cd AkanNameGenerator
<!-- List branches available -->
git branch -a
输出:
<!-- The asterix indicates we are on branch main -->
* main
remotes/origin/HEAD -> origin/main
remotes/origin/gh-pages
remotes/origin/main
我们将使用下面的命令切换到特定的分支 gh-pages
。
git checkout gh-pages
我们将通过运行确认我们在特定的分支 gh-pages
中:
git branch
输出:
<!-- The asterix indicates we are now on branch gh-pages -->
* gh-pages
main
直接从远程仓库克隆特定的 Git 分支
我们将通过在 Git 命令中指定分支名称,直接从远程仓库克隆我们需要的特定分支。
<!-- The command to use is -->
git clone --branch <branchname> --single-branch <remote-repo-url>
<!-- From your terminal run -->
git clone --branch gh-pages --single-branch https://github.com/KEVINAMAYI/AkanNameGenerator.git
输出:
Cloning into 'AkanNameGenerator'...
remote: Enumerating objects: 94, done.
remote: Total 94 (delta 0), reused 0 (delta 0), pack-reused 94
Unpacking objects: 100% (94/94), 2.38 MiB | 231.00 KiB/s, done.
我们将进入项目文件夹并通过运行以下命令列出可用的分支。
<!-- get into project folder -->
cd AkanNameGenerator
<!-- List branches available -->
git branch -a
输出:
<!-- we have only our specific branch -->
* gh-pages
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布,任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站。本站所有源码与软件均为原作者提供,仅供学习和研究使用。如您对本站的相关版权有任何异议,或者认为侵犯了您的合法权益,请及时通知我们处理。