git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* Why won't git checkout a branch?
@ 2020-07-01  8:41 Jeffrey Walton
  2020-07-01  9:50 ` Andreas Schwab
  0 siblings, 1 reply; 6+ messages in thread
From: Jeffrey Walton @ 2020-07-01  8:41 UTC (permalink / raw)
  To: Git List

Why can't I checkout a branch? What's broken this time?

$ rm -rf libb2
$ git clone https://github.com/noloader/libb2
Cloning into 'libb2'...
remote: Enumerating objects: 39, done.
remote: Counting objects: 100% (39/39), done.
remote: Compressing objects: 100% (31/31), done.
remote: Total 291 (delta 14), reused 23 (delta 8), pack-reused 252
Receiving objects: 100% (291/291), 431.67 KiB | 4.23 MiB/s, done.
Resolving deltas: 100% (162/162), done.
$ cd libb2
$ git fetch --all
Fetching origin
$ git branch -a
* master
  remotes/origin/HEAD -> origin/master
  remotes/origin/autotools
  remotes/origin/fix-bigendian
  remotes/origin/m4
  remotes/origin/master
  remotes/origin/overhaul
$ git checkout m4
$ git branch
* master

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Why won't git checkout a branch?
  2020-07-01  8:41 Why won't git checkout a branch? Jeffrey Walton
@ 2020-07-01  9:50 ` Andreas Schwab
  2020-07-01 10:09   ` Jeffrey Walton
  0 siblings, 1 reply; 6+ messages in thread
From: Andreas Schwab @ 2020-07-01  9:50 UTC (permalink / raw)
  To: Jeffrey Walton; +Cc: Git List

On Jul 01 2020, Jeffrey Walton wrote:

> $ git checkout m4

Try a newer git version:

$ git checkout m4
fatal: 'm4' could be both a local file and a tracking branch.
Please use -- (and optionally --no-guess) to disambiguate

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: Why won't git checkout a branch?
  2020-07-01  9:50 ` Andreas Schwab
@ 2020-07-01 10:09   ` Jeffrey Walton
  2020-07-01 10:20     ` Andreas Schwab
  2020-07-01 15:13     ` Chris Torek
  0 siblings, 2 replies; 6+ messages in thread
From: Jeffrey Walton @ 2020-07-01 10:09 UTC (permalink / raw)
  To: Andreas Schwab; +Cc: Git List

On Wed, Jul 1, 2020 at 5:50 AM Andreas Schwab <schwab@linux-m68k.org> wrote:
>
> On Jul 01 2020, Jeffrey Walton wrote:
>
> > $ git checkout m4
>
> Try a newer git version:
>
> $ git checkout m4
> fatal: 'm4' could be both a local file and a tracking branch.
> Please use -- (and optionally --no-guess) to disambiguate

Ack, thanks.

This does not look normal, either. I don't want to create a new
branch. I want to work on the existing branch.

$ git checkout origin/m4
Note: checking out 'origin/m4'.

You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by performing another checkout.

If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -b with the checkout command again. Example:

  git checkout -b <new-branch-name>

HEAD is now at 5c3967f Merge branch 'm4' of
https://github.com/noloader/libb2 into m4

Jeff

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Why won't git checkout a branch?
  2020-07-01 10:09   ` Jeffrey Walton
@ 2020-07-01 10:20     ` Andreas Schwab
  2020-07-01 10:45       ` Jeffrey Walton
  2020-07-01 15:13     ` Chris Torek
  1 sibling, 1 reply; 6+ messages in thread
From: Andreas Schwab @ 2020-07-01 10:20 UTC (permalink / raw)
  To: Jeffrey Walton; +Cc: Git List

On Jul 01 2020, Jeffrey Walton wrote:

> On Wed, Jul 1, 2020 at 5:50 AM Andreas Schwab <schwab@linux-m68k.org> wrote:
>>
>> On Jul 01 2020, Jeffrey Walton wrote:
>>
>> > $ git checkout m4
>>
>> Try a newer git version:
>>
>> $ git checkout m4
>> fatal: 'm4' could be both a local file and a tracking branch.
>> Please use -- (and optionally --no-guess) to disambiguate
>
> Ack, thanks.
>
> This does not look normal, either. I don't want to create a new
> branch. I want to work on the existing branch.

To disambiguate, use `git checkout m4 --' if you want the branch, and
`git checkout -- m4' if you want the local file.

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: Why won't git checkout a branch?
  2020-07-01 10:20     ` Andreas Schwab
@ 2020-07-01 10:45       ` Jeffrey Walton
  0 siblings, 0 replies; 6+ messages in thread
From: Jeffrey Walton @ 2020-07-01 10:45 UTC (permalink / raw)
  To: Andreas Schwab; +Cc: Git List

On Wed, Jul 1, 2020 at 6:20 AM Andreas Schwab <schwab@linux-m68k.org> wrote:
>
> On Jul 01 2020, Jeffrey Walton wrote:
>
> > On Wed, Jul 1, 2020 at 5:50 AM Andreas Schwab <schwab@linux-m68k.org> wrote:
> >>
> >> On Jul 01 2020, Jeffrey Walton wrote:
> >>
> >> > $ git checkout m4
> >>
> >> Try a newer git version:
> >>
> >> $ git checkout m4
> >> fatal: 'm4' could be both a local file and a tracking branch.
> >> Please use -- (and optionally --no-guess) to disambiguate
> >
> > Ack, thanks.
> >
> > This does not look normal, either. I don't want to create a new
> > branch. I want to work on the existing branch.
>
> To disambiguate, use `git checkout m4 --' if you want the branch, and
> `git checkout -- m4' if you want the local file.

Perfect, thanks.

So the way to checkout that always works is to append --. Is that correct?

If so, I will start using it everywhere.

Jeff

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Why won't git checkout a branch?
  2020-07-01 10:09   ` Jeffrey Walton
  2020-07-01 10:20     ` Andreas Schwab
@ 2020-07-01 15:13     ` Chris Torek
  1 sibling, 0 replies; 6+ messages in thread
From: Chris Torek @ 2020-07-01 15:13 UTC (permalink / raw)
  To: noloader; +Cc: Andreas Schwab, Git List

On Wed, Jul 1, 2020 at 3:10 AM Jeffrey Walton <noloader@gmail.com> wrote:
> This does not look normal, either. I don't want to create a new
> branch. I want to work on the existing branch.

Technically, you *have to* create a new branch here: you do
not have an `m4` branch (yet). Your local repository's branches
are independent of the branches in the repository you cloned.

(You could work in detached HEAD state to avoid the technical
requirement here but that's not practical for normal humans. :-) )

The suffix-`--` trick works in old versions of Git, creating the `m4`
branch from the `origin/m4` name.  If you upgrade to Git 2.23 or
later and use `git switch`, I think you will find that it's generally
more user friendly.

Chris

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2020-07-01 15:13 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-01  8:41 Why won't git checkout a branch? Jeffrey Walton
2020-07-01  9:50 ` Andreas Schwab
2020-07-01 10:09   ` Jeffrey Walton
2020-07-01 10:20     ` Andreas Schwab
2020-07-01 10:45       ` Jeffrey Walton
2020-07-01 15:13     ` Chris Torek

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).