Git 克隆一个分支,而不是 master

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/41965720/
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 04:46:09  来源:igfitidea点击:

Git clone a branch, not master

gitbranchbitbucketgit-bashgit-clone

提问by mister_giga

I use Git Bash for bitbucket. I have created a bunch and I pushed some commits, other people pushed commits in master as excepted. Now I am at different machine. I want to clone or download the solution of the latest commit of my branch and not the master? How can I do that?

我将 Git Bash 用于 bitbucket。我创建了一堆,我推送了一些提交,其他人推送了 master 中的提交作为例外。现在我在不同的机器上。我想克隆或下载我的分支而不是 master 的最新提交的解决方案?我怎样才能做到这一点?

回答by chepner

I think you are looking for the --branchoption to git clone, which allows you to specify which branch is initially checked out in the cloned repository.

我认为您正在寻找--branch选项git clone,它允许您指定最初在克隆的存储库中检出哪个分支。

git clone --branch mybranch $URL/foo

is roughly equivalent to

大致相当于

git clone $URL/foo
cd foo
git checkout mybranch
cd ..

回答by czar008

if you use git you can do that easily with git clone -b <name_of_branch> <URL_Repository>, if you want to pull do git pull origin <name_of_branch> <URL_Repository>.

如果你使用 git 你可以很容易地做到这一点git clone -b <name_of_branch> <URL_Repository>,如果你想拉 do git pull origin <name_of_branch> <URL_Repository>

Regards

问候

回答by Paras

You can use below solution:-

您可以使用以下解决方案:-

Step1: Clone the repo by using below command following by credentials.

步骤 1:使用以下命令和凭据克隆存储库。

git clone <Repository URL>

Step 2: checkout the branch and pull the latest code from there.

第 2 步:检出分支并从那里提取最新代码。

git checkout -b <your origin branch>

Step 3: pull the latest code

第三步:拉取最新代码

git pull origin <your origin branch name where latest code is there>