如何在 git bitbucket 中克隆特定分支

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/29981000/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 03:09:48  来源:igfitidea点击:

How to clone a specific branch in git bitbucket

gitgithubbitbucketgit-svn

提问by ruby student

I want to clone a specific branch. I don't want download the masterbranch.

我想克隆一个特定的分支。我不想下载master分支。

How do I clone the whole project and then switch to validationsbranch?

如何克隆整个项目然后切换到validations分支?

回答by sfletche

You can clone a single branch (without inadvertently cloning the whole project) with the following:

您可以使用以下命令克隆单个分支(不会无意中克隆整个项目):

git clone <url> --branch <branch> --single-branch [<folder>]

Alternatively (attempting to address your new question here...), you can clone the whole project

或者(尝试在此处解决您的新问题...),您可以克隆整个项目

git clone <url> 

Change directories into the folder and creating a new branch off of master with

将目录更改为文件夹并使用 master 创建一个新分支

git checkout -b validations

回答by mohamed murashid

git clone -b branchName remote_repo_url

For example git clone -b develop https://github.com/SundeepK/CompactCalendarView.git

例如 git clone -b develop https://github.com/SundeepK/CompactCalendarView.git

回答by Vishu

Use git clone as following :

使用 git clone 如下:

git clone -b specific/Branch --single-branch git://sub.domain.com/repo.git

And, Helpful link is

而且,有用的链接是

https://git-scm.com/docs/git-clone/1.7.10

https://git-scm.com/docs/git-clone/1.7.10

Also, If you get an error with "--single-branch", then removed it -b will work for you.

此外,如果您收到“--single-branch”错误,则将其删除 -b 对您有用。

回答by Sourabh Dev

To pull a separate branch, you need to follow two simple steps.

要拉出单独的分支,您需要遵循两个简单的步骤。

1. Create a new branch

1.新建一个分支

2. Pull the required branch

2. 拉取需要的分支

Try using the following commands:

尝试使用以下命令:

git checkout -b <new-branch-name>
git pull origin <branch-to-pull>

You will now have all the contents in the <new-branch-name>branch

您现在将拥有<new-branch-name>分支中的所有内容

回答by Satyam Anand

once you're done adding your ssh key, you can follow up with: git clone -b <branch_name> <url_to_repository>

添加完 ssh 密钥后,您可以跟进: git clone -b <branch_name> <url_to_repository>

replace all angular brackets with your required branch name and repository URL.

用您所需的分支名称和存储库 URL 替换所有尖括号。