git/contrib/completion
Junio C Hamano 05e2ab1f31 completion: 'git checkout' completes untracked paths as a last resort
We taught 'git checkout' to first try to complete revisions (unless
'--' is present on the command line) and, failing that, to complete
tracked paths.  If this yields nothing, it lets the Bash default,
which offers paths in $PWD, kick in.

Teach it to complete untracked paths before giving up and letting
the Bash default kick in.  With this change,

    $ git -C another-directory checkout un<TAB>

finds the 'untracked' file in another-directory and offers it as a
completion candidate.

Note that this is of somewhat dubious value, as an untracked path by
definition does not exist in the index, so checking it out from the
index would not work well.  Even when used to check out the path
from a different branch, it is still of dubious value because it is
unlikely that a path tracked in another branch is lying untracked in
the working tree, as switching from a branch with the path to a
branch without it will normally remove the file in the working tree.

A better behavior probably is to detect the tree-ish argument on
the command line and offer paths with the given prefix as candidates,
but there is no __git_complete_from_tree() helper readily usable,
so mark this as #leftoverbits to wait for another day.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
2026-08-13 12:13:56 -07:00
..
.gitattributes completion: mark bash script as LF-only 2017-05-10 13:32:51 +09:00
git-completion.bash completion: 'git checkout' completes untracked paths as a last resort 2026-08-13 12:13:56 -07:00
git-completion.tcsh completion: tcsh: Fix regression by drop of wrapper functions 2021-08-18 13:58:27 -07:00
git-completion.zsh completion: fix zsh alias listing for subsection aliases 2026-02-19 10:13:20 -08:00
git-prompt.sh git-prompt: support custom 0-width PS1 markers 2024-08-20 08:28:19 -07:00
meson.build contrib/completion: install Bash completion 2025-04-22 08:26:12 -07:00