git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] Add completion for short options

From
Junio C Hamano <gitster@pobox.com>
Date
Nov 25, 2025, 16:42 UTC
Message-ID
<xmqq5xayt66k.fsf@gitster.g>
In-Reply-To
<pull.2100.git.git.1764052739534.gitgitgadget@gmail.com>
"Wiktor Mis via GitGitGadget" <gitgitgadget@gmail.com> writes:

As the large part of the completion script is about completing git subcommands and options to these subcommands, it seems that nobody noticed the lack of completion for options of "git" itself.

> Subject: Re: [PATCH] Add completion for short options

This title makes it appear much broader than what the patch does, which is to complete "git -<TAB>" with short options for the "git" potty.

    Subjct: [PATCH] completion: complete "git -<TAB>" with short options
perhaps.
> From: Wiktor Mis <mwiktor023@gmail.com>
>
> Git provided completion for long options but not the short ones
Complete the sentence with something like
    ... not the short ones for "git" itself.
Show 29 quoted lines
> Signed-off-by: Wiktor Mis <mwiktor023@gmail.com>
> ---
>     Add completion for short options
>
> Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-2100%2FWiktorro%2Fpatch-3-v1
> Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-2100/Wiktorro/patch-3-v1
> Pull-Request: https://github.com/git/git/pull/2100
>
>  contrib/completion/git-completion.bash | 10 ++++++++++
>  1 file changed, 10 insertions(+)
>
> diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
> index 73abea31b4..3f1d6c0955 100644
> --- a/contrib/completion/git-completion.bash
> +++ b/contrib/completion/git-completion.bash
> @@ -3916,6 +3916,16 @@ __git_main ()
>  			--help
>  			"
>  			;;
> +		-*)
> +			__gitcomp "
> +			-C
> +			-P
> +			-c
> +			-h
> +			-p
> +			-v
> +			"
> +			;;
When you type
    $ git -<TAB>

the current completion without this patch does nothing. The above change makes it instead show the listed six.

Which is a good enough incremental update, I guess.
I however wonder if a separate follow-up change to let
    $ git -<TAB>

to show completion for both short and long options make the world even a better place. With the current completion, even with this patch, you need to type double-dash-and-TAB to ask for list of long options.

Thanks, will queue.
Previous: Wiktor Mis via GitGitGadgetNext: Wiktor Mis via GitGitGadget
Message 2 of 7 in “Add completion for short options”
  1. Add completion for short optionsWiktor Mis via GitGitGadget, Nov 25, 2025
  2. Junio C HamanoNov 25, 2025
  3. completion: complete "git -<TAB>" with short optionsWiktor Mis via GitGitGadget, Nov 26, 2025
  4. Junio C HamanoNov 26, 2025
  5. SZEDER GáborNov 27, 2025
  6. Junio C HamanoNov 27, 2025
  7. Junio C HamanoDec 7, 2025

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.