Git 在未出生的本地分支上签出远程分支
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1700167/
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
Git checkout remote branch on unborn local branch
提问by Andrei Serdeliuc ?
How would you accomplish this?
你将如何实现这一点?
mkdir newbuild
cd newbuild
git init
git remote add origin git+ssh://user@host:22/var/www/vhosts/build
$ git checkout -b origin/mybranch
fatal: You are on a branch yet to be born
回答by Lily Ballard
What are you trying to do here? You don't have an origin remote, so you don't have any remote branches, so you can't create a local branch based off of one. You need to either clone the remote repository, or add it as your origin remote and then git fetch
.
你想在这里做什么?您没有 origin 远程,因此您没有任何远程分支,因此您无法基于一个创建本地分支。您需要克隆远程存储库,或将其添加为您的原始远程存储库,然后git fetch
.
Of course, the error message is completely wrong. Ignore it.
当然,错误信息是完全错误的。忽略它。
回答by Pat Notz
I assume that origin
's active/default branch isn't mybranch
which is why a plain clone won't work. It might also be easier to just do this:
我认为origin
's active/default 分支不是mybranch
,这就是普通克隆不起作用的原因。这样做也可能更容易:
git clone -n git+ssh://user@host:22/var/www/vhosts/build newbuild
cd newbuild
git checkout -b origin/mybranch
回答by VonC
Note that, since Git1.8.0.1 (26th of November 2012): "git checkout -b foo
" while on an unborn branch did not say "Switched to a new branch 'foo'
" like other cases.
请注意,自 Git1.8.0.1(2012 年 11 月 26 日)以来:“ git checkout -b foo
” while 在未出生的分支上并没有Switched to a new branch 'foo'
像其他情况一样说“ ”。
It does now, see this commit.
现在可以了,请参阅此提交。