* Re: Can't checkout branch
2020-07-14 18:17 ` Chris Torek
@ 2020-07-14 19:04 ` Junio C Hamano
2020-07-14 20:29 ` Larry Martell
2020-07-15 7:00 ` Andreas Schwab
2 siblings, 0 replies; 6+ messages in thread
From: Junio C Hamano @ 2020-07-14 19:04 UTC (permalink / raw)
To: Chris Torek; +Cc: Larry Martell, Git List
Chris Torek <chris.torek@gmail.com> writes:
> 2. Treat this as `git checkout -b deploy origin/deploy`
> or `git checkout -t origin/deploy`, i.e., create the
> branch `deploy` from `origin/deploy`.
>
> If *both* of these alternatives work, pre-2.23 Git *assumes* you
> meant alternative number 1. In 2.23 or later, `git checkout`
> tells you that this is ambiguous and makes you pick which one you
> want.
>
> To work around this in all versions of Git, you can just be
> more explicit. For instance:
>
> git checkout deploy --
>
> forces Git to treat it as a branch name.
I actually think "git checkout -t -b deploy origin/deploy" is a
better way to be explicit to avoid confusion. You do not create a
branch every few seconds anyway---it is more important to instill in
user's head what really does go on by encouraging them to give these
command line arguments explicitly, instead of teaching new people to
rely on "git guesses most of the time in your favor so here is the
lazy command line"---that will prevent true understanding and if it
left unremedied long enough, will result in a confused user who is
no longer a newbie.
Having said that, yes "git checkout deploy --" is a way to still
rely on git guessing most of the time in your favor to stay lazy,
and it should work, but there may be unseen other factors to break
the DWIM, just like Larry didn't think of an existing file deploy
in the working tree to be interfering.
Thanks.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Can't checkout branch
2020-07-14 18:17 ` Chris Torek
2020-07-14 19:04 ` Junio C Hamano
@ 2020-07-14 20:29 ` Larry Martell
2020-07-15 7:00 ` Andreas Schwab
2 siblings, 0 replies; 6+ messages in thread
From: Larry Martell @ 2020-07-14 20:29 UTC (permalink / raw)
To: Chris Torek; +Cc: Git List
On Tue, Jul 14, 2020 at 2:18 PM Chris Torek <chris.torek@gmail.com> wrote:
>
> On Tue, Jul 14, 2020 at 10:04 AM Larry Martell <larry.martell@gmail.com> wrote:
> [snippage]
> > $ git fetch --all
> > Fetching origin
> > * [new branch] deploy -> origin/deploy
> >
> > $ git checkout deploy
> > $ git branch
> > * master
> >
> > $ git checkout origin/deploy
> > Note: checking out 'origin/deploy'.
> >
> > You are in 'detached HEAD' state.
> >
> > I tried deleting the local repo and recloning, but I got the same
> > results. I see the branch on github. I can checkout other branches,
> > just not this one.
> >
> > What could be going on?
>
> This happens in Git versions prior to 2.23 (what Git version are
> you using?) when there is a *file or directory* named `deploy`.
>
> What is happening is that since there is no *branch* named
> deploy (yet), you can't check it out (yet). So `git checkout
> deploy` initially fails. The checkout command then goes on
> to try two alternatives:
>
> 1. Treat this as `git checkout -- deploy`, i.e.,
> extract the file or subtree named `deploy` from
> the index (discarding changes to that file or
> subtree).
>
> 2. Treat this as `git checkout -b deploy origin/deploy`
> or `git checkout -t origin/deploy`, i.e., create the
> branch `deploy` from `origin/deploy`.
>
> If *both* of these alternatives work, pre-2.23 Git *assumes* you
> meant alternative number 1. In 2.23 or later, `git checkout`
> tells you that this is ambiguous and makes you pick which one you
> want.
>
> To work around this in all versions of Git, you can just be
> more explicit. For instance:
>
> git checkout deploy --
>
> forces Git to treat it as a branch name.
Thanks for the reply - that was indeed the issue - I had a dir named deploy.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Can't checkout branch
2020-07-14 18:17 ` Chris Torek
2020-07-14 19:04 ` Junio C Hamano
2020-07-14 20:29 ` Larry Martell
@ 2020-07-15 7:00 ` Andreas Schwab
2020-07-15 14:50 ` Junio C Hamano
2 siblings, 1 reply; 6+ messages in thread
From: Andreas Schwab @ 2020-07-15 7:00 UTC (permalink / raw)
To: Chris Torek; +Cc: Larry Martell, Git List
On Jul 14 2020, Chris Torek wrote:
> To work around this in all versions of Git, you can just be
> more explicit. For instance:
>
> git checkout deploy --
>
> forces Git to treat it as a branch name.
For recent versions of git, you can also use `git switch deploy'.
Andreas.
--
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510 2552 DF73 E780 A9DA AEC1
"And now for something completely different."
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Can't checkout branch
2020-07-15 7:00 ` Andreas Schwab
@ 2020-07-15 14:50 ` Junio C Hamano
0 siblings, 0 replies; 6+ messages in thread
From: Junio C Hamano @ 2020-07-15 14:50 UTC (permalink / raw)
To: Andreas Schwab; +Cc: Chris Torek, Larry Martell, Git List
Andreas Schwab <schwab@linux-m68k.org> writes:
> On Jul 14 2020, Chris Torek wrote:
>
>> To work around this in all versions of Git, you can just be
>> more explicit. For instance:
>>
>> git checkout deploy --
>>
>> forces Git to treat it as a branch name.
>
> For recent versions of git, you can also use `git switch deploy'.
Yes, that is the best piece of advice in the thread so far.
Thanks.
^ permalink raw reply [flat|nested] 6+ messages in thread