# New checkout --track behaviour?

4 messages from 2024-12-12 to 2024-12-13. Participants: Francesco Occhipinti, brian m. carlson, Junio C Hamano.
Thread: https://gitlist.dev/t/62630

## Francesco Occhipinti, 2024-12-12 10:29

Subject: New checkout --track behaviour?
Message-ID: <DB9PR08MB71949D21F5F0E81911F0D50F903F2@DB9PR08MB7194.eurprd08.prod.outlook.com>
URL: https://gitlist.dev/e/DB9PR08MB71949D21F5F0E81911F0D50F903F2%40DB9PR08MB7194.eurprd08.prod.outlook.com
In-Reply-To: <DB9PR08MB7194822B81F17420B2D3C149903F2@DB9PR08MB7194.eurprd08.prod.outlook.com>

```
Hello,

Did the interface change in recent git versions? I am pretty sure i
used to git checkout -tb new_branch, now getting error: option
`--track' expects "direct" or "inherit".

User `geirha` on libera#git helped me troubleshooting. They noticed that:

- git help checkout differs in its description of --track between
  2.34.1 (ubuntu 22.04) and 2.43.0 (ubuntu 24.04), so looks like it
  did change recently

- according to the commit message at
  https://github.com/git/git/commit/6327f0efed36c64d98a140110171362b7cb75a52,
  -t is supposed to be equivalent to --track=direct, so likely a bug
  rather than intentional change

I did read all options in `man git config` looking for something
related. Found only branch.autoSetupMerge, but neither setting it to
`always` nor `inherit` helped

Cheers,
fran

```

## brian m. carlson, 2024-12-13 03:48

Subject: Re: New checkout --track behaviour?
Message-ID: <Z1uuqKI_2rb0HXhP@tapette.crustytoothpaste.net>
URL: https://gitlist.dev/e/Z1uuqKI_2rb0HXhP%40tapette.crustytoothpaste.net
In-Reply-To: <DB9PR08MB71949D21F5F0E81911F0D50F903F2@DB9PR08MB7194.eurprd08.prod.outlook.com>

```
On 2024-12-12 at 10:29:59, Francesco Occhipinti wrote:
> Hello,
> 
> Did the interface change in recent git versions? I am pretty sure i
> used to git checkout -tb new_branch, now getting error: option
> `--track' expects "direct" or "inherit".
> 
> User `geirha` on libera#git helped me troubleshooting. They noticed that:
> 
> - git help checkout differs in its description of --track between
>   2.34.1 (ubuntu 22.04) and 2.43.0 (ubuntu 24.04), so looks like it
>   did change recently
> 
> - according to the commit message at
>   https://github.com/git/git/commit/6327f0efed36c64d98a140110171362b7cb75a52,
>   -t is supposed to be equivalent to --track=direct, so likely a bug
>   rather than intentional change

`-t`, or `--track`, now takes an optional argument.  Before, it didn't,
so `-tb` was interpreted as `--track -b`.  Now, it's interpreted as
`--track=b`, since the `b` is interpreted as the option value to
`--track`.  That's not a valid value, so you get the error message.

This is indeed a subtle incompatibility in command-line option parsing,
but it's not really avoidable and it does occur in pretty much any case
where a short option learns to take an optional argument (for any
software, not just Git).  So what you probably want to do is `git
checkout -t -b new_branch`, and it will work as before.  That will also
work on older versions as well, so if you have scripts or aliases that
need to work across versions, that should be a safe syntax to use.
-- 
brian m. carlson (they/them or he/him)
Toronto, Ontario, CA

```

## Junio C Hamano, 2024-12-13 10:39

Subject: Re: New checkout --track behaviour?
Message-ID: <xmqqed2beujw.fsf@gitster.g>
URL: https://gitlist.dev/e/xmqqed2beujw.fsf%40gitster.g
In-Reply-To: <Z1uuqKI_2rb0HXhP@tapette.crustytoothpaste.net>

```
"brian m. carlson" <sandals@crustytoothpaste.net> writes:

> This is indeed a subtle incompatibility in command-line option parsing,
> but it's not really avoidable and it does occur in pretty much any case
> where a short option learns to take an optional argument (for any
> software, not just Git).

Perhaps we'd want something along this line?  While it is not really
avoidable if we have to add an optional value to an existing option,
"not really avoidable" is not a very satisfactory explanation to
please those whose established use cases they have, or their
scripts, have got broken.

--- >8 ------ >8 ------ >8 ---
Subject: gitcli: explain why short options are better spelled separately

When the "--track" option of "git checkout" command learned to take
an optional value a few years ago at d3115660 (branch: add flags and
config to inherit tracking, 2021-12-20), "git checkout -tb foo" got
broken, as it is no longer two options "--track" and "--branch=foo"
given together, but "--track=b" and a regular argument "foo".  The
command parser dies upon seeing "-tb" saying "b" is not a valid
optional value to "-t".

We already discourage users to spell short options in stuck form,
and if they spelled "-t -b foo", they would not have noticed this
breakage.  Add a bit more words to "git help cli" to explain why
we discourage the stuck form.

We might also want to add a note to ourselves (perhaps next to the
Documentation/CodingGuidelines, we'd want design guidelines) to
think very carefully before considering to introduce an option that
takes an optional value, and refrain from adding an optional value
to an existing option.  It would save the end users from confusion.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
 Documentation/gitcli.txt | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git c/Documentation/gitcli.txt w/Documentation/gitcli.txt
index bd62cbd043..dcc0aa5bf7 100644
--- c/Documentation/gitcli.txt
+++ w/Documentation/gitcli.txt
@@ -82,7 +82,9 @@ Here are the rules regarding the "flags" that you should follow when you are
 scripting Git:
 
  * Splitting short options to separate words (prefer `git foo -a -b`
-   to `git foo -ab`, the latter may not even work).
+   to `git foo -ab`, the latter may not even work, and even if it
+   worked, it will change the meaning once the '-a' option starts
+   taking an optional value).
 
  * When a command-line option takes an argument, use the 'stuck' form.  In
    other words, write `git foo -oArg` instead of `git foo -o Arg` for short

```

## Francesco Occhipinti, 2024-12-13 10:50

Subject: Re: New checkout --track behaviour?
Message-ID: <DB9PR08MB7194FF8C95C92AF26E1B8F1F90382@DB9PR08MB7194.eurprd08.prod.outlook.com>
URL: https://gitlist.dev/e/DB9PR08MB7194FF8C95C92AF26E1B8F1F90382%40DB9PR08MB7194.eurprd08.prod.outlook.com
In-Reply-To: <Z1uuqKI_2rb0HXhP@tapette.crustytoothpaste.net>

```
Yes, that works! Thanks Brian

________________________________________
From: brian m. carlson <sandals@crustytoothpaste.net>
Sent: Friday, December 13, 2024 4:48 AM
To: Francesco Occhipinti <Francesco.Occhipinti@tracsis.com>
Cc: git@vger.kernel.org <git@vger.kernel.org>
Subject: Re: New checkout --track behaviour?
 
[You don't often get email from sandals@crustytoothpaste.net. Learn why this is important at https://aka.ms/LearnAboutSenderIdentification ]

CAUTION: This email originated from outside of the organisation. Do not click links or open attachments unless you recognise the sender and know the content is safe.

```
