在克隆之前更改 SSH 远程上的 Git 分支

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

Change Git branch on SSH remote before cloning

gitsshbranchclone

提问by SwissChocolate

I am trying to clone a repo from an SSH remote like this:

我正在尝试从 SSH 远程克隆一个 repo,如下所示:

git clone "ssh://[email protected]/var/www/git/www"

This works OK but using this command I am actually cloning the "master" branch of the repo, but instead I want to clone another branch which is called "dev2".

这工作正常,但使用此命令我实际上是在克隆 repo 的“master”分支,但我想克隆另一个名为“dev2”的分支。

How do I achieve that?

我如何做到这一点?

回答by Kit Ho

after git clone.

在 git clone 之后。

you can just

你可以

git branch --track dev2 origin/dev2
git checkout dev2

git branch --track dev2 origin/dev2
git checkout dev2

to change your branch to dev2 easily.

轻松地将您的分支更改为 dev2。

or a short cut

或捷径

git clone -b dev2 "ssh://[email protected]/var/www/git/www"

回答by knittl

with git you generally clone complete repositories (all branches). if you want to clone only a single branch and never get any other branches use the following commands:

使用 git,您通常会克隆完整的存储库(所有分支)。如果您只想克隆一个分支并且永远不会获得任何其他分支,请使用以下命令:

git init project
cd project
git remote add -f -t dev2 origin 'ssh://[email protected]/var/www/git/www'
git checkout -b dev2 origin/dev2