3 # bash/zsh completion support for core Git.
5 # Copyright (C) 2006,2007 Shawn O. Pearce <spearce@spearce.org>
6 # Conceptually based on gitcompletion (http://gitweb.hawaga.org.uk/).
7 # Distributed under the GNU General Public License, version 2.0.
9 # The contained completion routines provide support for completing:
11 # *) local and remote branch names
12 # *) local and remote tag names
13 # *) .git/remotes file names
14 # *) git 'subcommands'
15 # *) tree paths within 'ref:path/to/file' expressions
16 # *) file paths within current working directory and index
17 # *) common --long-options
19 # To use these routines:
21 # 1) Copy this file to somewhere (e.g. ~/.git-completion.sh).
22 # 2) Add the following line to your .bashrc/.zshrc:
23 # source ~/.git-completion.sh
24 # 3) Consider changing your PS1 to also show the current branch,
25 # see git-prompt.sh for details.
27 case "$COMP_WORDBREAKS" in
29 *) COMP_WORDBREAKS="$COMP_WORDBREAKS:"
32 # __gitdir accepts 0 or 1 arguments (i.e., location)
33 # returns location of .git repo
36 # Note: this function is duplicated in git-prompt.sh
37 # When updating it, make sure you update the other one to match.
38 if [ -z "${1-}" ]; then
39 if [ -n "${__git_dir-}" ]; then
41 elif [ -n "${GIT_DIR-}" ]; then
42 test -d "${GIT_DIR-}" || return 1
44 elif [ -d .git ]; then
47 git rev-parse --git-dir 2>/dev/null
49 elif [ -d "$1/.git" ]; then
56 # The following function is based on code from:
58 # bash_completion - programmable completion functions for bash 3.2+
60 # Copyright © 2006-2008, Ian Macdonald <ian@caliban.org>
61 # © 2009-2010, Bash Completion Maintainers
62 # <bash-completion-devel@lists.alioth.debian.org>
64 # This program is free software; you can redistribute it and/or modify
65 # it under the terms of the GNU General Public License as published by
66 # the Free Software Foundation; either version 2, or (at your option)
69 # This program is distributed in the hope that it will be useful,
70 # but WITHOUT ANY WARRANTY; without even the implied warranty of
71 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
72 # GNU General Public License for more details.
74 # You should have received a copy of the GNU General Public License
75 # along with this program; if not, write to the Free Software Foundation,
76 # Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
78 # The latest version of this software can be obtained here:
80 # http://bash-completion.alioth.debian.org/
84 # This function can be used to access a tokenized list of words
85 # on the command line:
87 # __git_reassemble_comp_words_by_ref '=:'
88 # if test "${words_[cword_-1]}" = -w
93 # The argument should be a collection of characters from the list of
94 # word completion separators (COMP_WORDBREAKS) to treat as ordinary
97 # This is roughly equivalent to going back in time and setting
98 # COMP_WORDBREAKS to exclude those characters. The intent is to
99 # make option types like --date=<type> and <rev>:<path> easy to
100 # recognize by treating each shell word as a single token.
102 # It is best not to set COMP_WORDBREAKS directly because the value is
103 # shared with other completion scripts. By the time the completion
104 # function gets called, COMP_WORDS has already been populated so local
105 # changes to COMP_WORDBREAKS have no effect.
107 # Output: words_, cword_, cur_.
109 __git_reassemble_comp_words_by_ref()
111 local exclude i j first
112 # Which word separators to exclude?
113 exclude="${1//[^$COMP_WORDBREAKS]}"
115 if [ -z "$exclude" ]; then
116 words_=("${COMP_WORDS[@]}")
119 # List of word completion separators has shrunk;
120 # re-assemble words to complete.
121 for ((i=0, j=0; i < ${#COMP_WORDS[@]}; i++, j++)); do
122 # Append each nonempty word consisting of just
123 # word separator characters to the current word.
127 [ -n "${COMP_WORDS[$i]}" ] &&
128 # word consists of excluded word separators
129 [ "${COMP_WORDS[$i]//[^$exclude]}" = "${COMP_WORDS[$i]}" ]
131 # Attach to the previous token,
132 # unless the previous token is the command name.
133 if [ $j -ge 2 ] && [ -n "$first" ]; then
137 words_[$j]=${words_[j]}${COMP_WORDS[i]}
138 if [ $i = $COMP_CWORD ]; then
141 if (($i < ${#COMP_WORDS[@]} - 1)); then
148 words_[$j]=${words_[j]}${COMP_WORDS[i]}
149 if [ $i = $COMP_CWORD ]; then
155 if ! type _get_comp_words_by_ref >/dev/null 2>&1; then
156 _get_comp_words_by_ref ()
158 local exclude cur_ words_ cword_
159 if [ "$1" = "-n" ]; then
163 __git_reassemble_comp_words_by_ref "$exclude"
164 cur_=${words_[cword_]}
165 while [ $# -gt 0 ]; do
171 prev=${words_[$cword_-1]}
174 words=("${words_[@]}")
189 if [[ "$x" == "$3"* ]]; then
190 COMPREPLY[i++]="$2$x$4"
195 # Generates completion reply, appending a space to possible completion words,
197 # It accepts 1 to 4 arguments:
198 # 1: List of possible completion words.
199 # 2: A prefix to be added to each possible completion word (optional).
200 # 3: Generate possible completion matches for this word (optional).
201 # 4: A suffix to be appended to each possible completion word (optional).
204 local cur_="${3-$cur}"
210 local c i=0 IFS=$' \t\n'
213 if [[ $c == "$cur_"* ]]; then
218 COMPREPLY[i++]="${2-}$c"
225 # Generates completion reply from newline-separated possible completion words
226 # by appending a space to all of them.
227 # It accepts 1 to 4 arguments:
228 # 1: List of possible completion words, separated by a single newline.
229 # 2: A prefix to be added to each possible completion word (optional).
230 # 3: Generate possible completion matches for this word (optional).
231 # 4: A suffix to be appended to each possible completion word instead of
232 # the default space (optional). If specified but empty, nothing is
237 __gitcompadd "$1" "${2-}" "${3-$cur}" "${4- }"
240 # Generates completion reply with compgen from newline-separated possible
241 # completion filenames.
242 # It accepts 1 to 3 arguments:
243 # 1: List of possible completion filenames, separated by a single newline.
244 # 2: A directory prefix to be added to each possible completion filename
246 # 3: Generate possible completion matches for this word (optional).
251 # XXX does not work when the directory prefix contains a tilde,
252 # since tilde expansion is not applied.
253 # This means that COMPREPLY will be empty and Bash default
254 # completion will be used.
255 __gitcompadd "$1" "${2-}" "${3-$cur}" ""
257 # Tell Bash that compspec generates filenames.
258 compopt -o filenames 2>/dev/null
261 __git_index_file_list_filter_compat ()
265 while read -r path; do
267 ?*/*) echo "${path%%/*}/" ;;
273 __git_index_file_list_filter_bash ()
277 while read -r path; do
280 # XXX if we append a slash to directory names when using
281 # `compopt -o filenames`, Bash will append another slash.
282 # This is pretty stupid, and this the reason why we have to
283 # define a compatible version for this function.
284 echo "${path%%/*}" ;;
291 # Process path list returned by "ls-files" and "diff-index --name-only"
292 # commands, in order to list only file names relative to a specified
293 # directory, and append a slash to directory names.
294 __git_index_file_list_filter ()
296 # Default to Bash >= 4.x
297 __git_index_file_list_filter_bash
300 # Execute git ls-files, returning paths relative to the directory
301 # specified in the first argument, and using the options specified in
302 # the second argument.
303 __git_ls_files_helper ()
306 test -n "${CDPATH+set}" && unset CDPATH
307 # NOTE: $2 is not quoted in order to support multiple options
308 cd "$1" && git ls-files --exclude-standard $2
313 # Execute git diff-index, returning paths relative to the directory
314 # specified in the first argument, and using the tree object id
315 # specified in the second argument.
316 __git_diff_index_helper ()
319 test -n "${CDPATH+set}" && unset CDPATH
320 cd "$1" && git diff-index --name-only --relative "$2"
324 # __git_index_files accepts 1 or 2 arguments:
325 # 1: Options to pass to ls-files (required).
326 # 2: A directory path (optional).
327 # If provided, only files within the specified directory are listed.
328 # Sub directories are never recursed. Path must have a trailing
332 local dir="$(__gitdir)" root="${2-.}"
334 if [ -d "$dir" ]; then
335 __git_ls_files_helper "$root" "$1" | __git_index_file_list_filter |
340 # __git_diff_index_files accepts 1 or 2 arguments:
341 # 1) The id of a tree object.
342 # 2) A directory path (optional).
343 # If provided, only files within the specified directory are listed.
344 # Sub directories are never recursed. Path must have a trailing
346 __git_diff_index_files ()
348 local dir="$(__gitdir)" root="${2-.}"
350 if [ -d "$dir" ]; then
351 __git_diff_index_helper "$root" "$1" | __git_index_file_list_filter |
358 local dir="$(__gitdir)"
359 if [ -d "$dir" ]; then
360 git --git-dir="$dir" for-each-ref --format='%(refname:short)' \
368 local dir="$(__gitdir)"
369 if [ -d "$dir" ]; then
370 git --git-dir="$dir" for-each-ref --format='%(refname:short)' \
376 # __git_refs accepts 0, 1 (to pass to __gitdir), or 2 arguments
377 # presence of 2nd argument means use the guess heuristic employed
378 # by checkout for tracking branches
381 local i hash dir="$(__gitdir "${1-}")" track="${2-}"
383 if [ -d "$dir" ]; then
391 for i in HEAD FETCH_HEAD ORIG_HEAD MERGE_HEAD; do
392 if [ -e "$dir/$i" ]; then echo $i; fi
394 format="refname:short"
395 refs="refs/tags refs/heads refs/remotes"
398 git --git-dir="$dir" for-each-ref --format="%($format)" \
400 if [ -n "$track" ]; then
401 # employ the heuristic used by git checkout
402 # Try to find a remote branch that matches the completion word
403 # but only output if the branch name is unique
405 git --git-dir="$dir" for-each-ref --shell --format="ref=%(refname:short)" \
407 while read -r entry; do
410 if [[ "$ref" == "$cur"* ]]; then
413 done | sort | uniq -u
419 git ls-remote "$dir" "$cur*" 2>/dev/null | \
420 while read -r hash i; do
428 git ls-remote "$dir" HEAD ORIG_HEAD 'refs/tags/*' 'refs/heads/*' 'refs/remotes/*' 2>/dev/null | \
429 while read -r hash i; do
432 refs/*) echo "${i#refs/*/}" ;;
440 # __git_refs2 requires 1 argument (to pass to __git_refs)
444 for i in $(__git_refs "$1"); do
449 # __git_refs_remotes requires 1 argument (to pass to ls-remote)
450 __git_refs_remotes ()
453 git ls-remote "$1" 'refs/heads/*' 2>/dev/null | \
454 while read -r hash i; do
455 echo "$i:refs/remotes/$1/${i#refs/heads/}"
461 local i IFS=$'\n' d="$(__gitdir)"
462 test -d "$d/remotes" && ls -1 "$d/remotes"
463 for i in $(git --git-dir="$d" config --get-regexp 'remote\..*\.url' 2>/dev/null); do
469 __git_list_merge_strategies ()
471 git merge -s help 2>&1 |
472 sed -n -e '/[Aa]vailable strategies are: /,/^$/{
481 __git_merge_strategies=
482 # 'git merge -s help' (and thus detection of the merge strategy
483 # list) fails, unfortunately, if run outside of any git working
484 # tree. __git_merge_strategies is set to the empty string in
485 # that case, and the detection will be repeated the next time it
487 __git_compute_merge_strategies ()
489 test -n "$__git_merge_strategies" ||
490 __git_merge_strategies=$(__git_list_merge_strategies)
493 __git_complete_revlist_file ()
495 local pfx ls ref cur_="$cur"
515 case "$COMP_WORDBREAKS" in
517 *) pfx="$ref:$pfx" ;;
520 __gitcomp_nl "$(git --git-dir="$(__gitdir)" ls-tree "$ls" 2>/dev/null \
521 | sed '/^100... blob /{
537 pfx="${cur_%...*}..."
539 __gitcomp_nl "$(__git_refs)" "$pfx" "$cur_"
544 __gitcomp_nl "$(__git_refs)" "$pfx" "$cur_"
547 __gitcomp_nl "$(__git_refs)"
553 # __git_complete_index_file requires 1 argument: the options to pass to
555 __git_complete_index_file ()
557 local pfx cur_="$cur"
565 __gitcomp_file "$(__git_index_files "$1" "$pfx")" "$pfx" "$cur_"
568 __gitcomp_file "$(__git_index_files "$1")" "" "$cur_"
573 # __git_complete_diff_index_file requires 1 argument: the id of a tree
575 __git_complete_diff_index_file ()
577 local pfx cur_="$cur"
585 __gitcomp_file "$(__git_diff_index_files "$1" "$pfx")" "$pfx" "$cur_"
588 __gitcomp_file "$(__git_diff_index_files "$1")" "" "$cur_"
593 __git_complete_file ()
595 __git_complete_revlist_file
598 __git_complete_revlist ()
600 __git_complete_revlist_file
603 __git_complete_remote_or_refspec ()
605 local cur_="$cur" cmd="${words[1]}"
606 local i c=2 remote="" pfx="" lhs=1 no_complete_refspec=0
607 if [ "$cmd" = "remote" ]; then
610 while [ $c -lt $cword ]; do
613 --mirror) [ "$cmd" = "push" ] && no_complete_refspec=1 ;;
616 push) no_complete_refspec=1 ;;
624 *) remote="$i"; break ;;
628 if [ -z "$remote" ]; then
629 __gitcomp_nl "$(__git_remotes)"
632 if [ $no_complete_refspec = 1 ]; then
635 [ "$remote" = "." ] && remote=
638 case "$COMP_WORDBREAKS" in
640 *) pfx="${cur_%%:*}:" ;;
652 if [ $lhs = 1 ]; then
653 __gitcomp_nl "$(__git_refs2 "$remote")" "$pfx" "$cur_"
655 __gitcomp_nl "$(__git_refs)" "$pfx" "$cur_"
659 if [ $lhs = 1 ]; then
660 __gitcomp_nl "$(__git_refs "$remote")" "$pfx" "$cur_"
662 __gitcomp_nl "$(__git_refs)" "$pfx" "$cur_"
666 if [ $lhs = 1 ]; then
667 __gitcomp_nl "$(__git_refs)" "$pfx" "$cur_"
669 __gitcomp_nl "$(__git_refs "$remote")" "$pfx" "$cur_"
675 __git_complete_strategy ()
677 __git_compute_merge_strategies
680 __gitcomp "$__git_merge_strategies"
685 __gitcomp "$__git_merge_strategies" "" "${cur##--strategy=}"
693 if test -n "${GIT_TESTING_COMMAND_COMPLETION:-}"
695 printf "%s" "${GIT_TESTING_COMMAND_COMPLETION}"
697 git help -a|egrep '^ [a-zA-Z0-9]'
701 __git_list_all_commands ()
704 for i in $(__git_commands)
707 *--*) : helper pattern;;
714 __git_compute_all_commands ()
716 test -n "$__git_all_commands" ||
717 __git_all_commands=$(__git_list_all_commands)
720 __git_list_porcelain_commands ()
723 __git_compute_all_commands
724 for i in $__git_all_commands
727 *--*) : helper pattern;;
728 applymbox) : ask gittus;;
729 applypatch) : ask gittus;;
730 archimport) : import;;
731 cat-file) : plumbing;;
732 check-attr) : plumbing;;
733 check-ignore) : plumbing;;
734 check-ref-format) : plumbing;;
735 checkout-index) : plumbing;;
736 commit-tree) : plumbing;;
737 count-objects) : infrequent;;
738 credential-cache) : credentials helper;;
739 credential-store) : credentials helper;;
740 cvsexportcommit) : export;;
741 cvsimport) : import;;
742 cvsserver) : daemon;;
744 diff-files) : plumbing;;
745 diff-index) : plumbing;;
746 diff-tree) : plumbing;;
747 fast-import) : import;;
748 fast-export) : export;;
749 fsck-objects) : plumbing;;
750 fetch-pack) : plumbing;;
751 fmt-merge-msg) : plumbing;;
752 for-each-ref) : plumbing;;
753 hash-object) : plumbing;;
754 http-*) : transport;;
755 index-pack) : plumbing;;
756 init-db) : deprecated;;
757 local-fetch) : plumbing;;
758 lost-found) : infrequent;;
759 ls-files) : plumbing;;
760 ls-remote) : plumbing;;
761 ls-tree) : plumbing;;
762 mailinfo) : plumbing;;
763 mailsplit) : plumbing;;
764 merge-*) : plumbing;;
767 pack-objects) : plumbing;;
768 pack-redundant) : plumbing;;
769 pack-refs) : plumbing;;
770 parse-remote) : plumbing;;
771 patch-id) : plumbing;;
772 peek-remote) : plumbing;;
774 prune-packed) : plumbing;;
775 quiltimport) : import;;
776 read-tree) : plumbing;;
777 receive-pack) : plumbing;;
778 remote-*) : transport;;
779 repo-config) : deprecated;;
781 rev-list) : plumbing;;
782 rev-parse) : plumbing;;
783 runstatus) : plumbing;;
784 sh-setup) : internal;;
786 show-ref) : plumbing;;
787 send-pack) : plumbing;;
788 show-index) : plumbing;;
790 stripspace) : plumbing;;
791 symbolic-ref) : plumbing;;
792 tar-tree) : deprecated;;
793 unpack-file) : plumbing;;
794 unpack-objects) : plumbing;;
795 update-index) : plumbing;;
796 update-ref) : plumbing;;
797 update-server-info) : daemon;;
798 upload-archive) : plumbing;;
799 upload-pack) : plumbing;;
800 write-tree) : plumbing;;
802 verify-pack) : infrequent;;
803 verify-tag) : plumbing;;
809 __git_porcelain_commands=
810 __git_compute_porcelain_commands ()
812 __git_compute_all_commands
813 test -n "$__git_porcelain_commands" ||
814 __git_porcelain_commands=$(__git_list_porcelain_commands)
817 __git_pretty_aliases ()
820 for i in $(git --git-dir="$(__gitdir)" config --get-regexp "pretty\..*" 2>/dev/null); do
833 for i in $(git --git-dir="$(__gitdir)" config --get-regexp "alias\..*" 2>/dev/null); do
843 # __git_aliased_command requires 1 argument
844 __git_aliased_command ()
846 local word cmdline=$(git --git-dir="$(__gitdir)" \
847 config --get "alias.$1")
848 for word in $cmdline; do
854 \!*) : shell command alias ;;
856 *=*) : setting env ;;
865 # __git_find_on_cmdline requires 1 argument
866 __git_find_on_cmdline ()
868 local word subcommand c=1
869 while [ $c -lt $cword ]; do
871 for subcommand in $1; do
872 if [ "$subcommand" = "$word" ]; then
881 __git_has_doubledash ()
884 while [ $c -lt $cword ]; do
885 if [ "--" = "${words[c]}" ]; then
893 # Try to count non option arguments passed on the command line for the
894 # specified git command.
895 # When options are used, it is necessary to use the special -- option to
896 # tell the implementation were non option arguments begin.
897 # XXX this can not be improved, since options can appear everywhere, as
901 # __git_count_arguments requires 1 argument: the git command executed.
902 __git_count_arguments ()
906 # Skip "git" (first argument)
907 for ((i=1; i < ${#words[@]}; i++)); do
912 # Good; we can assume that the following are only non
917 # Skip the specified git command and discard git
930 __git_whitespacelist="nowarn warn error error-all fix"
934 local dir="$(__gitdir)"
935 if [ -d "$dir"/rebase-apply ]; then
936 __gitcomp "--skip --continue --resolved --abort"
941 __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
946 --3way --committer-date-is-author-date --ignore-date
947 --ignore-whitespace --ignore-space-change
948 --interactive --keep --no-utf8 --signoff --utf8
949 --whitespace= --scissors
959 __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
964 --stat --numstat --summary --check --index
965 --cached --index-info --reverse --reject --unidiff-zero
966 --apply --no-add --exclude=
967 --ignore-whitespace --ignore-space-change
968 --whitespace= --inaccurate-eof --verbose
979 --interactive --refresh --patch --update --dry-run
980 --ignore-errors --intent-to-add
985 # XXX should we check for --update and --all options ?
986 __git_complete_index_file "--others --modified"
993 __gitcomp "$(git archive --list)" "" "${cur##--format=}"
997 __gitcomp_nl "$(__git_remotes)" "" "${cur##--remote=}"
1002 --format= --list --verbose
1003 --prefix= --remote= --exec=
1013 __git_has_doubledash && return
1015 local subcommands="start bad good skip reset visualize replay log run"
1016 local subcommand="$(__git_find_on_cmdline "$subcommands")"
1017 if [ -z "$subcommand" ]; then
1018 if [ -f "$(__gitdir)"/BISECT_START ]; then
1019 __gitcomp "$subcommands"
1021 __gitcomp "replay start"
1026 case "$subcommand" in
1027 bad|good|reset|skip|start)
1028 __gitcomp_nl "$(__git_refs)"
1037 local i c=1 only_local_ref="n" has_r="n"
1039 while [ $c -lt $cword ]; do
1042 -d|-m) only_local_ref="y" ;;
1049 --set-upstream-to=*)
1050 __gitcomp "$(__git_refs)" "" "${cur##--set-upstream-to=}"
1054 --color --no-color --verbose --abbrev= --no-abbrev
1055 --track --no-track --contains --merged --no-merged
1056 --set-upstream-to= --edit-description --list
1061 if [ $only_local_ref = "y" -a $has_r = "n" ]; then
1062 __gitcomp_nl "$(__git_heads)"
1064 __gitcomp_nl "$(__git_refs)"
1072 local cmd="${words[2]}"
1075 __gitcomp "create list-heads verify unbundle"
1078 # looking for a file
1083 __git_complete_revlist
1092 __git_has_doubledash && return
1096 __gitcomp "diff3 merge" "" "${cur##--conflict=}"
1100 --quiet --ours --theirs --track --no-track --merge
1101 --conflict= --orphan --patch
1105 # check if --track, --no-track, or --no-guess was specified
1106 # if so, disable DWIM mode
1107 local flags="--track --no-track --no-guess" track=1
1108 if [ -n "$(__git_find_on_cmdline "$flags")" ]; then
1111 __gitcomp_nl "$(__git_refs '' $track)"
1118 __gitcomp "$(__git_refs)"
1123 local dir="$(__gitdir)"
1124 if [ -f "$dir"/CHERRY_PICK_HEAD ]; then
1125 __gitcomp "--continue --quit --abort"
1130 __gitcomp "--edit --no-commit --signoff --strategy= --mainline"
1133 __gitcomp_nl "$(__git_refs)"
1142 __gitcomp "--dry-run --quiet"
1147 # XXX should we check for -x option ?
1148 __git_complete_index_file "--others"
1180 __gitcomp_nl "$(__git_refs)" "" "${cur}"
1187 __gitcomp "default strip verbatim whitespace
1188 " "" "${cur##--cleanup=}"
1191 --reuse-message=*|--reedit-message=*|\
1192 --fixup=*|--squash=*)
1193 __gitcomp_nl "$(__git_refs)" "" "${cur#*=}"
1196 --untracked-files=*)
1197 __gitcomp "all no normal" "" "${cur##--untracked-files=}"
1202 --all --author= --signoff --verify --no-verify
1204 --amend --include --only --interactive
1205 --dry-run --reuse-message= --reedit-message=
1206 --reset-author --file= --message= --template=
1207 --cleanup= --untracked-files --untracked-files=
1208 --verbose --quiet --fixup= --squash=
1213 if git rev-parse --verify --quiet HEAD >/dev/null; then
1214 __git_complete_diff_index_file "HEAD"
1216 # This is the first commit
1217 __git_complete_index_file "--cached"
1226 --all --tags --contains --abbrev= --candidates=
1227 --exact-match --debug --long --match --always
1231 __gitcomp_nl "$(__git_refs)"
1234 __git_diff_algorithms="myers minimal patience histogram"
1236 __git_diff_common_options="--stat --numstat --shortstat --summary
1237 --patch-with-stat --name-only --name-status --color
1238 --no-color --color-words --no-renames --check
1239 --full-index --binary --abbrev --diff-filter=
1240 --find-copies-harder
1241 --text --ignore-space-at-eol --ignore-space-change
1242 --ignore-all-space --exit-code --quiet --ext-diff
1244 --no-prefix --src-prefix= --dst-prefix=
1245 --inter-hunk-context=
1246 --patience --histogram --minimal
1248 --dirstat --dirstat= --dirstat-by-file
1249 --dirstat-by-file= --cumulative
1255 __git_has_doubledash && return
1259 __gitcomp "$__git_diff_algorithms" "" "${cur##--diff-algorithm=}"
1263 __gitcomp "--cached --staged --pickaxe-all --pickaxe-regex
1264 --base --ours --theirs --no-index
1265 $__git_diff_common_options
1270 __git_complete_revlist_file
1273 __git_mergetools_common="diffuse ecmerge emerge kdiff3 meld opendiff
1274 tkdiff vimdiff gvimdiff xxdiff araxis p4merge bc3 codecompare
1279 __git_has_doubledash && return
1283 __gitcomp "$__git_mergetools_common kompare" "" "${cur##--tool=}"
1287 __gitcomp "--cached --staged --pickaxe-all --pickaxe-regex
1288 --base --ours --theirs
1289 --no-renames --diff-filter= --find-copies-harder
1290 --relative --ignore-submodules
1298 __git_fetch_options="
1299 --quiet --verbose --append --upload-pack --force --keep --depth=
1300 --tags --no-tags --all --prune --dry-run
1307 __gitcomp "$__git_fetch_options"
1311 __git_complete_remote_or_refspec
1314 __git_format_patch_options="
1315 --stdout --attach --no-attach --thread --thread= --output-directory
1316 --numbered --start-number --numbered-files --keep-subject --signoff
1317 --signature --no-signature --in-reply-to= --cc= --full-index --binary
1318 --not --all --cover-letter --no-prefix --src-prefix= --dst-prefix=
1319 --inline --suffix= --ignore-if-in-upstream --subject-prefix=
1322 _git_format_patch ()
1328 " "" "${cur##--thread=}"
1332 __gitcomp "$__git_format_patch_options"
1336 __git_complete_revlist
1344 --tags --root --unreachable --cache --no-reflogs --full
1345 --strict --verbose --lost-found
1356 __gitcomp "--prune --aggressive"
1367 __git_match_ctag() {
1368 awk "/^${1////\\/}/ { print \$1 }" "$2"
1373 __git_has_doubledash && return
1379 --text --ignore-case --word-regexp --invert-match
1380 --full-name --line-number
1381 --extended-regexp --basic-regexp --fixed-strings
1383 --files-with-matches --name-only
1384 --files-without-match
1387 --and --or --not --all-match
1393 case "$cword,$prev" in
1395 if test -r tags; then
1396 __gitcomp_nl "$(__git_match_ctag "$cur" tags)"
1402 __gitcomp_nl "$(__git_refs)"
1409 __gitcomp "--all --info --man --web"
1413 __git_compute_all_commands
1414 __gitcomp "$__git_all_commands $(__git_aliases)
1415 attributes cli core-tutorial cvs-migration
1416 diffcore gitk glossary hooks ignore modules
1417 namespaces repository-layout tutorial tutorial-2
1427 false true umask group all world everybody
1428 " "" "${cur##--shared=}"
1432 __gitcomp "--quiet --bare --template= --shared --shared="
1442 __gitcomp "--cached --deleted --modified --others --ignored
1443 --stage --directory --no-empty-directory --unmerged
1444 --killed --exclude= --exclude-from=
1445 --exclude-per-directory= --exclude-standard
1446 --error-unmatch --with-tree= --full-name
1447 --abbrev --ignored --exclude-per-directory
1453 # XXX ignore options like --modified and always suggest all cached
1455 __git_complete_index_file "--cached"
1460 __gitcomp_nl "$(__git_remotes)"
1468 # Options that go well for log, shortlog and gitk
1469 __git_log_common_options="
1471 --branches --tags --remotes
1472 --first-parent --merges --no-merges
1474 --max-age= --since= --after=
1475 --min-age= --until= --before=
1476 --min-parents= --max-parents=
1477 --no-min-parents --no-max-parents
1479 # Options that go well for log and gitk (not shortlog)
1480 __git_log_gitk_options="
1481 --dense --sparse --full-history
1482 --simplify-merges --simplify-by-decoration
1483 --left-right --notes --no-notes
1485 # Options that go well for log and shortlog (not gitk)
1486 __git_log_shortlog_options="
1487 --author= --committer= --grep=
1491 __git_log_pretty_formats="oneline short medium full fuller email raw format:"
1492 __git_log_date_formats="relative iso8601 rfc2822 short local default raw"
1496 __git_has_doubledash && return
1498 local g="$(git rev-parse --git-dir 2>/dev/null)"
1500 if [ -f "$g/MERGE_HEAD" ]; then
1504 --pretty=*|--format=*)
1505 __gitcomp "$__git_log_pretty_formats $(__git_pretty_aliases)
1510 __gitcomp "$__git_log_date_formats" "" "${cur##--date=}"
1514 __gitcomp "long short" "" "${cur##--decorate=}"
1519 $__git_log_common_options
1520 $__git_log_shortlog_options
1521 $__git_log_gitk_options
1522 --root --topo-order --date-order --reverse
1523 --follow --full-diff
1524 --abbrev-commit --abbrev=
1525 --relative-date --date=
1526 --pretty= --format= --oneline
1529 --decorate --decorate=
1531 --parents --children
1533 $__git_diff_common_options
1534 --pickaxe-all --pickaxe-regex
1539 __git_complete_revlist
1542 __git_merge_options="
1543 --no-commit --no-stat --log --no-log --squash --strategy
1544 --commit --stat --no-squash --ff --no-ff --ff-only --edit --no-edit
1549 __git_complete_strategy && return
1553 __gitcomp "$__git_merge_options"
1556 __gitcomp_nl "$(__git_refs)"
1563 __gitcomp "$__git_mergetools_common tortoisemerge" "" "${cur##--tool=}"
1575 __gitcomp_nl "$(__git_refs)"
1582 __gitcomp "--dry-run"
1587 if [ $(__git_count_arguments "mv") -gt 0 ]; then
1588 # We need to show both cached and untracked files (including
1589 # empty directories) since this may not be the last argument.
1590 __git_complete_index_file "--cached --others --directory"
1592 __git_complete_index_file "--cached"
1598 __gitcomp "--tags --all --stdin"
1603 local subcommands='add append copy edit list prune remove show'
1604 local subcommand="$(__git_find_on_cmdline "$subcommands")"
1606 case "$subcommand,$cur" in
1613 __gitcomp_nl "$(__git_refs)"
1616 __gitcomp "$subcommands --ref"
1620 add,--reuse-message=*|append,--reuse-message=*|\
1621 add,--reedit-message=*|append,--reedit-message=*)
1622 __gitcomp_nl "$(__git_refs)" "" "${cur#*=}"
1625 __gitcomp '--file= --message= --reedit-message=
1632 __gitcomp '--dry-run --verbose'
1641 __gitcomp_nl "$(__git_refs)"
1650 __git_complete_strategy && return
1655 --rebase --no-rebase
1656 $__git_merge_options
1657 $__git_fetch_options
1662 __git_complete_remote_or_refspec
1669 __gitcomp_nl "$(__git_remotes)"
1674 __gitcomp_nl "$(__git_remotes)" "" "${cur##--repo=}"
1679 --all --mirror --tags --dry-run --force --verbose
1680 --receive-pack= --repo= --set-upstream
1685 __git_complete_remote_or_refspec
1690 local dir="$(__gitdir)"
1691 if [ -d "$dir"/rebase-apply ] || [ -d "$dir"/rebase-merge ]; then
1692 __gitcomp "--continue --skip --abort"
1695 __git_complete_strategy && return
1698 __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
1703 --onto --merge --strategy --interactive
1704 --preserve-merges --stat --no-stat
1705 --committer-date-is-author-date --ignore-date
1706 --ignore-whitespace --whitespace=
1712 __gitcomp_nl "$(__git_refs)"
1717 local subcommands="show delete expire"
1718 local subcommand="$(__git_find_on_cmdline "$subcommands")"
1720 if [ -z "$subcommand" ]; then
1721 __gitcomp "$subcommands"
1723 __gitcomp_nl "$(__git_refs)"
1727 __git_send_email_confirm_options="always never auto cc compose"
1728 __git_send_email_suppresscc_options="author self cc bodycc sob cccmd body all"
1735 $__git_send_email_confirm_options
1736 " "" "${cur##--confirm=}"
1741 $__git_send_email_suppresscc_options
1742 " "" "${cur##--suppress-cc=}"
1746 --smtp-encryption=*)
1747 __gitcomp "ssl tls" "" "${cur##--smtp-encryption=}"
1753 " "" "${cur##--thread=}"
1757 __gitcomp "--annotate --bcc --cc --cc-cmd --chain-reply-to
1758 --compose --confirm= --dry-run --envelope-sender
1760 --in-reply-to --no-chain-reply-to --no-signed-off-by-cc
1761 --no-suppress-from --no-thread --quiet
1762 --signed-off-by-cc --smtp-pass --smtp-server
1763 --smtp-server-port --smtp-encryption= --smtp-user
1764 --subject --suppress-cc= --suppress-from --thread --to
1765 --validate --no-validate
1766 $__git_format_patch_options"
1770 __git_complete_revlist
1778 __git_config_get_set_variables ()
1780 local prevword word config_file= c=$cword
1781 while [ $c -gt 1 ]; do
1784 --system|--global|--local|--file=*)
1789 config_file="$word $prevword"
1797 git --git-dir="$(__gitdir)" config $config_file --list 2>/dev/null |
1812 __gitcomp_nl "$(__git_remotes)"
1816 __gitcomp_nl "$(__git_refs)"
1820 local remote="${prev#remote.}"
1821 remote="${remote%.fetch}"
1822 if [ -z "$cur" ]; then
1823 __gitcompadd "refs/heads/" "" "" ""
1826 __gitcomp_nl "$(__git_refs_remotes "$remote")"
1830 local remote="${prev#remote.}"
1831 remote="${remote%.push}"
1832 __gitcomp_nl "$(git --git-dir="$(__gitdir)" \
1833 for-each-ref --format='%(refname):%(refname)' \
1837 pull.twohead|pull.octopus)
1838 __git_compute_merge_strategies
1839 __gitcomp "$__git_merge_strategies"
1842 color.branch|color.diff|color.interactive|\
1843 color.showbranch|color.status|color.ui)
1844 __gitcomp "always never auto"
1848 __gitcomp "false true"
1853 normal black red green yellow blue magenta cyan white
1854 bold dim ul blink reverse
1859 __gitcomp "man info web html"
1863 __gitcomp "$__git_log_date_formats"
1866 sendemail.aliasesfiletype)
1867 __gitcomp "mutt mailrc pine elm gnus"
1871 __gitcomp "$__git_send_email_confirm_options"
1874 sendemail.suppresscc)
1875 __gitcomp "$__git_send_email_suppresscc_options"
1878 --get|--get-all|--unset|--unset-all)
1879 __gitcomp_nl "$(__git_config_get_set_variables)"
1889 --system --global --local --file=
1890 --list --replace-all
1891 --get --get-all --get-regexp
1892 --add --unset --unset-all
1893 --remove-section --rename-section
1898 local pfx="${cur%.*}." cur_="${cur##*.}"
1899 __gitcomp "remote merge mergeoptions rebase" "$pfx" "$cur_"
1903 local pfx="${cur%.*}." cur_="${cur#*.}"
1904 __gitcomp_nl "$(__git_heads)" "$pfx" "$cur_" "."
1908 local pfx="${cur%.*}." cur_="${cur##*.}"
1910 argprompt cmd confirm needsfile noconsole norescan
1911 prompt revprompt revunmerged title
1916 local pfx="${cur%.*}." cur_="${cur##*.}"
1917 __gitcomp "cmd path" "$pfx" "$cur_"
1921 local pfx="${cur%.*}." cur_="${cur##*.}"
1922 __gitcomp "cmd path" "$pfx" "$cur_"
1926 local pfx="${cur%.*}." cur_="${cur##*.}"
1927 __gitcomp "cmd path trustExitCode" "$pfx" "$cur_"
1931 local pfx="${cur%.*}." cur_="${cur#*.}"
1932 __git_compute_all_commands
1933 __gitcomp_nl "$__git_all_commands" "$pfx" "$cur_"
1937 local pfx="${cur%.*}." cur_="${cur##*.}"
1939 url proxy fetch push mirror skipDefaultUpdate
1940 receivepack uploadpack tagopt pushurl
1945 local pfx="${cur%.*}." cur_="${cur#*.}"
1946 __gitcomp_nl "$(__git_remotes)" "$pfx" "$cur_" "."
1950 local pfx="${cur%.*}." cur_="${cur##*.}"
1951 __gitcomp "insteadOf pushInsteadOf" "$pfx" "$cur_"
1957 advice.commitBeforeMerge
1959 advice.implicitIdentity
1960 advice.pushNonFastForward
1961 advice.resolveConflict
1965 apply.ignorewhitespace
1967 branch.autosetupmerge
1968 branch.autosetuprebase
1972 color.branch.current
1977 color.decorate.branch
1978 color.decorate.remoteBranch
1979 color.decorate.stash
1989 color.diff.whitespace
1994 color.grep.linenumber
1997 color.grep.separator
1999 color.interactive.error
2000 color.interactive.header
2001 color.interactive.help
2002 color.interactive.prompt
2007 color.status.changed
2009 color.status.nobranch
2010 color.status.untracked
2011 color.status.updated
2020 core.bigFileThreshold
2023 core.deltaBaseCacheLimit
2028 core.fsyncobjectfiles
2030 core.ignoreCygwinFSTricks
2033 core.logAllRefUpdates
2034 core.loosecompression
2037 core.packedGitWindowSize
2039 core.preferSymlinkRefs
2042 core.repositoryFormatVersion
2044 core.sharedRepository
2048 core.warnAmbiguousRefs
2051 diff.autorefreshindex
2054 diff.ignoreSubmodules
2059 diff.suppressBlankEmpty
2065 fetch.recurseSubmodules
2074 format.subjectprefix
2085 gc.reflogexpireunreachable
2089 gitcvs.commitmsgannotation
2090 gitcvs.dbTableNamePrefix
2101 gui.copyblamethreshold
2105 gui.matchtrackingbranch
2106 gui.newbranchtemplate
2107 gui.pruneduringfetch
2108 gui.spellingdictionary
2123 http.sslCertPasswordProtected
2128 i18n.logOutputEncoding
2134 imap.preformattedHTML
2144 interactive.singlekey
2160 mergetool.keepBackup
2161 mergetool.keepTemporaries
2166 notes.rewrite.rebase
2170 pack.deltaCacheLimit
2186 receive.denyCurrentBranch
2187 receive.denyDeleteCurrent
2189 receive.denyNonFastForwards
2192 receive.updateserverinfo
2194 repack.usedeltabaseoffset
2198 sendemail.aliasesfile
2199 sendemail.aliasfiletype
2203 sendemail.chainreplyto
2205 sendemail.envelopesender
2209 sendemail.signedoffbycc
2210 sendemail.smtpdomain
2211 sendemail.smtpencryption
2213 sendemail.smtpserver
2214 sendemail.smtpserveroption
2215 sendemail.smtpserverport
2217 sendemail.suppresscc
2218 sendemail.suppressfrom
2223 status.relativePaths
2224 status.showUntrackedFiles
2225 status.submodulesummary
2228 transfer.unpackLimit
2240 local subcommands="add rename remove set-head set-branches set-url show prune update"
2241 local subcommand="$(__git_find_on_cmdline "$subcommands")"
2242 if [ -z "$subcommand" ]; then
2243 __gitcomp "$subcommands"
2247 case "$subcommand" in
2248 rename|remove|set-url|show|prune)
2249 __gitcomp_nl "$(__git_remotes)"
2251 set-head|set-branches)
2252 __git_complete_remote_or_refspec
2255 local i c='' IFS=$'\n'
2256 for i in $(git --git-dir="$(__gitdir)" config --get-regexp "remotes\..*" 2>/dev/null); do
2269 __gitcomp_nl "$(__git_refs)"
2274 __git_has_doubledash && return
2278 __gitcomp "--merge --mixed --hard --soft --patch"
2282 __gitcomp_nl "$(__git_refs)"
2289 __gitcomp "--edit --mainline --no-edit --no-commit --signoff"
2293 __gitcomp_nl "$(__git_refs)"
2300 __gitcomp "--cached --dry-run --ignore-unmatch --quiet"
2305 __git_complete_index_file "--cached"
2310 __git_has_doubledash && return
2315 $__git_log_common_options
2316 $__git_log_shortlog_options
2317 --numbered --summary
2322 __git_complete_revlist
2327 __git_has_doubledash && return
2330 --pretty=*|--format=*)
2331 __gitcomp "$__git_log_pretty_formats $(__git_pretty_aliases)
2336 __gitcomp "$__git_diff_algorithms" "" "${cur##--diff-algorithm=}"
2340 __gitcomp "--pretty= --format= --abbrev-commit --oneline
2341 $__git_diff_common_options
2354 --all --remotes --topo-order --current --more=
2355 --list --independent --merge-base --no-name
2357 --sha1-name --sparse --topics --reflog
2362 __git_complete_revlist
2367 local save_opts='--keep-index --no-keep-index --quiet --patch'
2368 local subcommands='save list show apply clear drop pop create branch'
2369 local subcommand="$(__git_find_on_cmdline "$subcommands")"
2370 if [ -z "$subcommand" ]; then
2373 __gitcomp "$save_opts"
2376 if [ -z "$(__git_find_on_cmdline "$save_opts")" ]; then
2377 __gitcomp "$subcommands"
2382 case "$subcommand,$cur" in
2384 __gitcomp "$save_opts"
2387 __gitcomp "--index --quiet"
2389 show,--*|drop,--*|branch,--*)
2391 show,*|apply,*|drop,*|pop,*|branch,*)
2392 __gitcomp_nl "$(git --git-dir="$(__gitdir)" stash list \
2393 | sed -n -e 's/:.*//p')"
2403 __git_has_doubledash && return
2405 local subcommands="add status init deinit update summary foreach sync"
2406 if [ -z "$(__git_find_on_cmdline "$subcommands")" ]; then
2409 __gitcomp "--quiet --cached"
2412 __gitcomp "$subcommands"
2422 init fetch clone rebase dcommit log find-rev
2423 set-tree commit-diff info create-ignore propget
2424 proplist show-ignore show-externals branch tag blame
2425 migrate mkdirs reset gc
2427 local subcommand="$(__git_find_on_cmdline "$subcommands")"
2428 if [ -z "$subcommand" ]; then
2429 __gitcomp "$subcommands"
2431 local remote_opts="--username= --config-dir= --no-auth-cache"
2433 --follow-parent --authors-file= --repack=
2434 --no-metadata --use-svm-props --use-svnsync-props
2435 --log-window-size= --no-checkout --quiet
2436 --repack-flags --use-log-author --localtime
2437 --ignore-paths= $remote_opts
2440 --template= --shared= --trunk= --tags=
2441 --branches= --stdlayout --minimize-url
2442 --no-metadata --use-svm-props --use-svnsync-props
2443 --rewrite-root= --prefix= --use-log-author
2444 --add-author-from $remote_opts
2447 --edit --rmdir --find-copies-harder --copy-similarity=
2450 case "$subcommand,$cur" in
2452 __gitcomp "--revision= --fetch-all $fc_opts"
2455 __gitcomp "--revision= $fc_opts $init_opts"
2458 __gitcomp "$init_opts"
2462 --merge --strategy= --verbose --dry-run
2463 --fetch-all --no-rebase --commit-url
2464 --revision --interactive $cmt_opts $fc_opts
2468 __gitcomp "--stdin $cmt_opts $fc_opts"
2470 create-ignore,--*|propget,--*|proplist,--*|show-ignore,--*|\
2471 show-externals,--*|mkdirs,--*)
2472 __gitcomp "--revision="
2476 --limit= --revision= --verbose --incremental
2477 --oneline --show-commit --non-recursive
2478 --authors-file= --color
2483 --merge --verbose --strategy= --local
2484 --fetch-all --dry-run $fc_opts
2488 __gitcomp "--message= --file= --revision= $cmt_opts"
2494 __gitcomp "--dry-run --message --tag"
2497 __gitcomp "--dry-run --message"
2500 __gitcomp "--git-format"
2504 --config-dir= --ignore-paths= --minimize
2505 --no-auth-cache --username=
2509 __gitcomp "--revision= --parent"
2520 while [ $c -lt $cword ]; do
2524 __gitcomp_nl "$(__git_tags)"
2539 __gitcomp_nl "$(__git_tags)"
2543 __gitcomp_nl "$(__git_refs)"
2555 local i c=1 command __git_dir
2557 while [ $c -lt $cword ]; do
2560 --git-dir=*) __git_dir="${i#--git-dir=}" ;;
2561 --bare) __git_dir="." ;;
2562 --help) command="help"; break ;;
2565 *) command="$i"; break ;;
2570 if [ -z "$command" ]; then
2584 --no-replace-objects
2588 *) __git_compute_porcelain_commands
2589 __gitcomp "$__git_porcelain_commands $(__git_aliases)" ;;
2594 local completion_func="_git_${command//-/_}"
2595 declare -f $completion_func >/dev/null && $completion_func && return
2597 local expansion=$(__git_aliased_command "$command")
2598 if [ -n "$expansion" ]; then
2599 completion_func="_git_${expansion//-/_}"
2600 declare -f $completion_func >/dev/null && $completion_func
2606 __git_has_doubledash && return
2608 local g="$(__gitdir)"
2610 if [ -f "$g/MERGE_HEAD" ]; then
2616 $__git_log_common_options
2617 $__git_log_gitk_options
2623 __git_complete_revlist
2626 if [[ -n ${ZSH_VERSION-} ]]; then
2627 echo "WARNING: this script is deprecated, please see git-completion.zsh" 1>&2
2629 autoload -U +X compinit && compinit
2635 local cur_="${3-$cur}"
2641 local c IFS=$' \t\n'
2649 array[$#array+1]="$c"
2652 compadd -Q -S '' -p "${2-}" -a -- array && _ret=0
2663 compadd -Q -S "${4- }" -p "${2-}" -- ${=1} && _ret=0
2672 compadd -Q -p "${2-}" -f -- ${=1} && _ret=0
2678 local cur cword prev
2679 cur=${words[CURRENT-1]}
2680 prev=${words[CURRENT-2]}
2690 let _ret && _default -S '' && _ret=0
2694 compdef _git git gitk
2696 elif [[ -n ${BASH_VERSION-} ]]; then
2697 if ((${BASH_VERSINFO[0]} < 4)); then
2698 # compopt is not supported
2699 __git_index_file_list_filter ()
2701 __git_index_file_list_filter_compat
2708 local cur words cword prev
2709 _get_comp_words_by_ref -n =: cur words cword prev
2713 # Setup completion for certain functions defined above by setting common
2714 # variables and workarounds.
2715 # This is NOT a public function; use at your own risk.
2718 local wrapper="__git_wrap${2}"
2719 eval "$wrapper () { __git_func_wrap $2 ; }"
2720 complete -o bashdefault -o default -o nospace -F $wrapper $1 2>/dev/null \
2721 || complete -o default -o nospace -F $wrapper $1
2724 # wrapper for backwards compatibility
2727 __git_wrap__git_main
2730 # wrapper for backwards compatibility
2733 __git_wrap__gitk_main
2736 __git_complete git __git_main
2737 __git_complete gitk __gitk_main
2739 # The following are necessary only for Cygwin, and only are needed
2740 # when the user has tab-completed the executable name and consequently
2741 # included the '.exe' suffix.
2743 if [ Cygwin = "$(uname -o 2>/dev/null)" ]; then
2744 __git_complete git.exe __git_main