# checkout -b remotes/origin/<branch> should not work

3 messages from 2017-05-14 to 2017-05-14. Participants: Stefan Beller, Jeff King, Junio C Hamano.
Thread: https://gitlist.dev/t/45957

## Stefan Beller, 2017-05-14 03:52

Subject: checkout -b remotes/origin/<branch> should not work
Message-ID: <CAGZ79kYACtA_q6kJ=gGYe02H-a9g_GV=kKLn8jy2ZZKvjxGYNQ@mail.gmail.com>
URL: https://gitlist.dev/e/CAGZ79kYACtA_q6kJ%3DgGYe02H-a9g_GV%3DkKLn8jy2ZZKvjxGYNQ%40mail.gmail.com

```
NEEDSWORK:

checkout -b remotes/origin/<branch> should not work, unless force is
given (maybe?)

(I just run into that, now I have a remote tracking branch that points
at my detached HEAD. Oh well.)

```

## Jeff King, 2017-05-14 04:00

Subject: Re: checkout -b remotes/origin/<branch> should not work
Message-ID: <20170514040048.evwtngo6bixtrput@sigill.intra.peff.net>
URL: https://gitlist.dev/e/20170514040048.evwtngo6bixtrput%40sigill.intra.peff.net
In-Reply-To: <CAGZ79kYACtA_q6kJ=gGYe02H-a9g_GV=kKLn8jy2ZZKvjxGYNQ@mail.gmail.com>

```
On Sat, May 13, 2017 at 08:52:37PM -0700, Stefan Beller wrote:

> NEEDSWORK:
> 
> checkout -b remotes/origin/<branch> should not work, unless force is
> given (maybe?)
> 
> (I just run into that, now I have a remote tracking branch that points
> at my detached HEAD. Oh well.)

To be pedantic, you have a local branch with a funny name that points to
your detached HEAD. :)

I think this problem extends beyond "remotes/". The worst is:

  git checkout -b HEAD

but there are many confusing variants:

  git checkout -b refs/heads/foo
  git checkout -b tags/v1.0

etc. Those are all perfectly legal names, but almost certainly not what
the user intended. I think the plumbing should continue to allow them,
but I wouldn't object to some common-sense think-o protections in the
"checkout -b" plumbing (especially if it could be disabled for power
users).

-Peff

```

## Junio C Hamano, 2017-05-14 08:00

Subject: Re: checkout -b remotes/origin/<branch> should not work
Message-ID: <xmqqefvr50m3.fsf@gitster.mtv.corp.google.com>
URL: https://gitlist.dev/e/xmqqefvr50m3.fsf%40gitster.mtv.corp.google.com
In-Reply-To: <20170514040048.evwtngo6bixtrput@sigill.intra.peff.net>

```
Jeff King <peff@peff.net> writes:

> I think this problem extends beyond "remotes/". The worst is:
>
>   git checkout -b HEAD
>
> but there are many confusing variants:
>
>   git checkout -b refs/heads/foo
>   git checkout -b tags/v1.0
>
> etc. Those are all perfectly legal names, but almost certainly not what
> the user intended. I think the plumbing should continue to allow them,
> but I wouldn't object to some common-sense think-o protections in the
> "checkout -b" plumbing (especially if it could be disabled for power
> users).

Yup.  I suspect that the last one has uses (for those who may want
to build on v1.0 tag it is conceivable that a local branch they use
for it is named like so), but I agree that anything that begins with
refs/* is not something any sane person would want to use.

sanity.branchname configuration or something that tells "checkout"
and "branch" Porcelain commands to barf on an attempt to create such
refnames does not sound too bad, and making it on by default may not
even be a bad idea.  But that leads me to say it may not even need
to be a configurable thing (people who DO want funny names can
already and still use the plumbing).

In any case, no command after such a change should forbid checking
out such a funny-named branch if it already exists.  We should
complain only on (an attempted) creation.



```
