Andrei Serdeliuc ॐ
Andrei Serdeliuc ॐ

Reputation: 5878

Git checkout remote branch on unborn local branch

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

Upvotes: 2

Views: 15433

Answers (3)

VonC
VonC

Reputation: 1323313

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.

Upvotes: 0

Pat Notz
Pat Notz

Reputation: 214196

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

Upvotes: 3

Lily Ballard
Lily Ballard

Reputation: 185661

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.

Upvotes: 6

Related Questions