开发者

Git checkout remote branch on unborn local branch

开发者 https://www.devze.com 2022-12-11 09:16 出处:网络
How would you accomplish this? mkdir newbuild cd newbuild git init git remote add origin git+ssh://user@host:22/var/www/vhosts/build开发者_如何学C

How would you accomplish this?

mkdir newbuild
cd newbuild
git init
git remote add origin git+ssh://user@host:22/var/www/vhosts/build开发者_如何学C
$ git checkout -b origin/mybranch
fatal: You are on a branch yet to be born


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.

Of course, the error message is completely wrong. Ignore it.


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:

git clone -n git+ssh://user@host:22/var/www/vhosts/build newbuild
cd newbuild
git checkout -b origin/mybranch


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.

It does now, see this commit.

0

精彩评论

暂无评论...
验证码 换一张
取 消