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
69 # The following function is based on code from:
71 # bash_completion - programmable completion functions for bash 3.2+
73 # Copyright © 2006-2008, Ian Macdonald <ian@caliban.org>
74 # © 2009-2010, Bash Completion Maintainers
75 # <bash-completion-devel@lists.alioth.debian.org>
77 # This program is free software; you can redistribute it and/or modify
78 # it under the terms of the GNU General Public License as published by
79 # the Free Software Foundation; either version 2, or (at your option)
82 # This program is distributed in the hope that it will be useful,
83 # but WITHOUT ANY WARRANTY; without even the implied warranty of
84 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
85 # GNU General Public License for more details.
87 # You should have received a copy of the GNU General Public License
88 # along with this program; if not, write to the Free Software Foundation,
89 # Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
91 # The latest version of this software can be obtained here:
93 # http://bash-completion.alioth.debian.org/
97 # This function can be used to access a tokenized list of words
98 # on the command line:
100 # __git_reassemble_comp_words_by_ref '=:'
101 # if test "${words_[cword_-1]}" = -w
106 # The argument should be a collection of characters from the list of
107 # word completion separators (COMP_WORDBREAKS) to treat as ordinary
110 # This is roughly equivalent to going back in time and setting
111 # COMP_WORDBREAKS to exclude those characters. The intent is to
112 # make option types like --date=<type> and <rev>:<path> easy to
113 # recognize by treating each shell word as a single token.
115 # It is best not to set COMP_WORDBREAKS directly because the value is
116 # shared with other completion scripts. By the time the completion
117 # function gets called, COMP_WORDS has already been populated so local
118 # changes to COMP_WORDBREAKS have no effect.
120 # Output: words_, cword_, cur_.
122 __git_reassemble_comp_words_by_ref()
124 local exclude i j first
125 # Which word separators to exclude?
126 exclude="${1//[^$COMP_WORDBREAKS]}"
128 if [ -z "$exclude" ]; then
129 words_=("${COMP_WORDS[@]}")
132 # List of word completion separators has shrunk;
133 # re-assemble words to complete.
134 for ((i=0, j=0; i < ${#COMP_WORDS[@]}; i++, j++)); do
135 # Append each nonempty word consisting of just
136 # word separator characters to the current word.
140 [ -n "${COMP_WORDS[$i]}" ] &&
141 # word consists of excluded word separators
142 [ "${COMP_WORDS[$i]//[^$exclude]}" = "${COMP_WORDS[$i]}" ]
144 # Attach to the previous token,
145 # unless the previous token is the command name.
146 if [ $j -ge 2 ] && [ -n "$first" ]; then
150 words_[$j]=${words_[j]}${COMP_WORDS[i]}
151 if [ $i = $COMP_CWORD ]; then
154 if (($i < ${#COMP_WORDS[@]} - 1)); then
161 words_[$j]=${words_[j]}${COMP_WORDS[i]}
162 if [ $i = $COMP_CWORD ]; then
168 if ! type _get_comp_words_by_ref >/dev/null 2>&1; then
169 _get_comp_words_by_ref ()
171 local exclude cur_ words_ cword_
172 if [ "$1" = "-n" ]; then
176 __git_reassemble_comp_words_by_ref "$exclude"
177 cur_=${words_[cword_]}
178 while [ $# -gt 0 ]; do
184 prev=${words_[$cword_-1]}
187 words=("${words_[@]}")
198 # Generates completion reply with compgen, appending a space to possible
199 # completion words, if necessary.
200 # It accepts 1 to 4 arguments:
201 # 1: List of possible completion words.
202 # 2: A prefix to be added to each possible completion word (optional).
203 # 3: Generate possible completion matches for this word (optional).
204 # 4: A suffix to be appended to each possible completion word (optional).
207 local cur_="${3-$cur}"
215 COMPREPLY=($(compgen -P "${2-}" \
216 -W "$(__gitcomp_1 "${1-}" "${4-}")" \
222 # Generates completion reply with compgen from newline-separated possible
223 # completion words by appending a space to all of them.
224 # It accepts 1 to 4 arguments:
225 # 1: List of possible completion words, separated by a single newline.
226 # 2: A prefix to be added to each possible completion word (optional).
227 # 3: Generate possible completion matches for this word (optional).
228 # 4: A suffix to be appended to each possible completion word instead of
229 # the default space (optional). If specified but empty, nothing is
234 COMPREPLY=($(compgen -P "${2-}" -S "${4- }" -W "$1" -- "${3-$cur}"))
237 # Generates completion reply with compgen from newline-separated possible
238 # completion filenames.
239 # It accepts 1 to 3 arguments:
240 # 1: List of possible completion filenames, separated by a single newline.
241 # 2: A directory prefix to be added to each possible completion filename
243 # 3: Generate possible completion matches for this word (optional).
248 # XXX does not work when the directory prefix contains a tilde,
249 # since tilde expansion is not applied.
250 # This means that COMPREPLY will be empty and Bash default
251 # completion will be used.
252 COMPREPLY=($(compgen -P "${2-}" -W "$1" -- "${3-$cur}"))
254 # Tell Bash that compspec generates filenames.
255 compopt -o filenames 2>/dev/null
258 __git_index_file_list_filter_compat ()
262 while read -r path; do
264 ?*/*) echo "${path%%/*}/" ;;
270 __git_index_file_list_filter_bash ()
274 while read -r path; do
277 # XXX if we append a slash to directory names when using
278 # `compopt -o filenames`, Bash will append another slash.
279 # This is pretty stupid, and this the reason why we have to
280 # define a compatible version for this function.
281 echo "${path%%/*}" ;;
288 # Process path list returned by "ls-files" and "diff-index --name-only"
289 # commands, in order to list only file names relative to a specified
290 # directory, and append a slash to directory names.
291 __git_index_file_list_filter ()
293 # Default to Bash >= 4.x
294 __git_index_file_list_filter_bash
297 # Execute git ls-files, returning paths relative to the directory
298 # specified in the first argument, and using the options specified in
299 # the second argument.
300 __git_ls_files_helper ()
303 test -n "${CDPATH+set}" && unset CDPATH
304 # NOTE: $2 is not quoted in order to support multiple options
305 cd "$1" && git ls-files --exclude-standard $2
310 # Execute git diff-index, returning paths relative to the directory
311 # specified in the first argument, and using the tree object id
312 # specified in the second argument.
313 __git_diff_index_helper ()
316 test -n "${CDPATH+set}" && unset CDPATH
317 cd "$1" && git diff-index --name-only --relative "$2"
321 # __git_index_files accepts 1 or 2 arguments:
322 # 1: Options to pass to ls-files (required).
323 # Supported options are --cached, --modified, --deleted, --others,
325 # 2: A directory path (optional).
326 # If provided, only files within the specified directory are listed.
327 # Sub directories are never recursed. Path must have a trailing
331 local dir="$(__gitdir)" root="${2-.}"
333 if [ -d "$dir" ]; then
334 __git_ls_files_helper "$root" "$1" | __git_index_file_list_filter |
339 # __git_diff_index_files accepts 1 or 2 arguments:
340 # 1) The id of a tree object.
341 # 2) A directory path (optional).
342 # If provided, only files within the specified directory are listed.
343 # Sub directories are never recursed. Path must have a trailing
345 __git_diff_index_files ()
347 local dir="$(__gitdir)" root="${2-.}"
349 if [ -d "$dir" ]; then
350 __git_diff_index_helper "$root" "$1" | __git_index_file_list_filter |
357 local dir="$(__gitdir)"
358 if [ -d "$dir" ]; then
359 git --git-dir="$dir" for-each-ref --format='%(refname:short)' \
367 local dir="$(__gitdir)"
368 if [ -d "$dir" ]; then
369 git --git-dir="$dir" for-each-ref --format='%(refname:short)' \
375 # __git_refs accepts 0, 1 (to pass to __gitdir), or 2 arguments
376 # presence of 2nd argument means use the guess heuristic employed
377 # by checkout for tracking branches
380 local i hash dir="$(__gitdir "${1-}")" track="${2-}"
382 if [ -d "$dir" ]; then
390 for i in HEAD FETCH_HEAD ORIG_HEAD MERGE_HEAD; do
391 if [ -e "$dir/$i" ]; then echo $i; fi
393 format="refname:short"
394 refs="refs/tags refs/heads refs/remotes"
397 git --git-dir="$dir" for-each-ref --format="%($format)" \
399 if [ -n "$track" ]; then
400 # employ the heuristic used by git checkout
401 # Try to find a remote branch that matches the completion word
402 # but only output if the branch name is unique
404 git --git-dir="$dir" for-each-ref --shell --format="ref=%(refname:short)" \
406 while read -r entry; do
409 if [[ "$ref" == "$cur"* ]]; then
412 done | sort | uniq -u
418 git ls-remote "$dir" "$cur*" 2>/dev/null | \
419 while read -r hash i; do
427 git ls-remote "$dir" HEAD ORIG_HEAD 'refs/tags/*' 'refs/heads/*' 'refs/remotes/*' 2>/dev/null | \
428 while read -r hash i; do
431 refs/*) echo "${i#refs/*/}" ;;
439 # __git_refs2 requires 1 argument (to pass to __git_refs)
443 for i in $(__git_refs "$1"); do
448 # __git_refs_remotes requires 1 argument (to pass to ls-remote)
449 __git_refs_remotes ()
452 git ls-remote "$1" 'refs/heads/*' 2>/dev/null | \
453 while read -r hash i; do
454 echo "$i:refs/remotes/$1/${i#refs/heads/}"
460 local i IFS=$'\n' d="$(__gitdir)"
461 test -d "$d/remotes" && ls -1 "$d/remotes"
462 for i in $(git --git-dir="$d" config --get-regexp 'remote\..*\.url' 2>/dev/null); do
468 __git_list_merge_strategies ()
470 git merge -s help 2>&1 |
471 sed -n -e '/[Aa]vailable strategies are: /,/^$/{
480 __git_merge_strategies=
481 # 'git merge -s help' (and thus detection of the merge strategy
482 # list) fails, unfortunately, if run outside of any git working
483 # tree. __git_merge_strategies is set to the empty string in
484 # that case, and the detection will be repeated the next time it
486 __git_compute_merge_strategies ()
488 test -n "$__git_merge_strategies" ||
489 __git_merge_strategies=$(__git_list_merge_strategies)
492 __git_complete_revlist_file ()
494 local pfx ls ref cur_="$cur"
514 case "$COMP_WORDBREAKS" in
516 *) pfx="$ref:$pfx" ;;
519 __gitcomp_nl "$(git --git-dir="$(__gitdir)" ls-tree "$ls" 2>/dev/null \
520 | sed '/^100... blob /{
536 pfx="${cur_%...*}..."
538 __gitcomp_nl "$(__git_refs)" "$pfx" "$cur_"
543 __gitcomp_nl "$(__git_refs)" "$pfx" "$cur_"
546 __gitcomp_nl "$(__git_refs)"
552 # __git_complete_index_file requires 1 argument: the options to pass to
554 __git_complete_index_file ()
556 local pfx cur_="$cur"
564 __gitcomp_file "$(__git_index_files "$1" "$pfx")" "$pfx" "$cur_"
567 __gitcomp_file "$(__git_index_files "$1")" "" "$cur_"
572 # __git_complete_diff_index_file requires 1 argument: the id of a tree
574 __git_complete_diff_index_file ()
576 local pfx cur_="$cur"
584 __gitcomp_file "$(__git_diff_index_files "$1" "$pfx")" "$pfx" "$cur_"
587 __gitcomp_file "$(__git_diff_index_files "$1")" "" "$cur_"
592 __git_complete_file ()
594 __git_complete_revlist_file
597 __git_complete_revlist ()
599 __git_complete_revlist_file
602 __git_complete_remote_or_refspec ()
604 local cur_="$cur" cmd="${words[1]}"
605 local i c=2 remote="" pfx="" lhs=1 no_complete_refspec=0
606 if [ "$cmd" = "remote" ]; then
609 while [ $c -lt $cword ]; do
612 --mirror) [ "$cmd" = "push" ] && no_complete_refspec=1 ;;
615 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
636 [ "$remote" = "." ] && remote=
639 case "$COMP_WORDBREAKS" in
641 *) pfx="${cur_%%:*}:" ;;
653 if [ $lhs = 1 ]; then
654 __gitcomp_nl "$(__git_refs2 "$remote")" "$pfx" "$cur_"
656 __gitcomp_nl "$(__git_refs)" "$pfx" "$cur_"
660 if [ $lhs = 1 ]; then
661 __gitcomp_nl "$(__git_refs "$remote")" "$pfx" "$cur_"
663 __gitcomp_nl "$(__git_refs)" "$pfx" "$cur_"
667 if [ $lhs = 1 ]; then
668 __gitcomp_nl "$(__git_refs)" "$pfx" "$cur_"
670 __gitcomp_nl "$(__git_refs "$remote")" "$pfx" "$cur_"
676 __git_complete_strategy ()
678 __git_compute_merge_strategies
681 __gitcomp "$__git_merge_strategies"
686 __gitcomp "$__git_merge_strategies" "" "${cur##--strategy=}"
694 if test -n "${GIT_TESTING_COMMAND_COMPLETION:-}"
696 printf "%s" "${GIT_TESTING_COMMAND_COMPLETION}"
698 git help -a|egrep '^ [a-zA-Z0-9]'
702 __git_list_all_commands ()
705 for i in $(__git_commands)
708 *--*) : helper pattern;;
715 __git_compute_all_commands ()
717 test -n "$__git_all_commands" ||
718 __git_all_commands=$(__git_list_all_commands)
721 __git_list_porcelain_commands ()
724 __git_compute_all_commands
725 for i in $__git_all_commands
728 *--*) : helper pattern;;
729 applymbox) : ask gittus;;
730 applypatch) : ask gittus;;
731 archimport) : import;;
732 cat-file) : plumbing;;
733 check-attr) : plumbing;;
734 check-ignore) : plumbing;;
735 check-ref-format) : plumbing;;
736 checkout-index) : plumbing;;
737 commit-tree) : plumbing;;
738 count-objects) : infrequent;;
739 credential-cache) : credentials helper;;
740 credential-store) : credentials helper;;
741 cvsexportcommit) : export;;
742 cvsimport) : import;;
743 cvsserver) : daemon;;
745 diff-files) : plumbing;;
746 diff-index) : plumbing;;
747 diff-tree) : plumbing;;
748 fast-import) : import;;
749 fast-export) : export;;
750 fsck-objects) : plumbing;;
751 fetch-pack) : plumbing;;
752 fmt-merge-msg) : plumbing;;
753 for-each-ref) : plumbing;;
754 hash-object) : plumbing;;
755 http-*) : transport;;
756 index-pack) : plumbing;;
757 init-db) : deprecated;;
758 local-fetch) : plumbing;;
759 lost-found) : infrequent;;
760 ls-files) : plumbing;;
761 ls-remote) : plumbing;;
762 ls-tree) : plumbing;;
763 mailinfo) : plumbing;;
764 mailsplit) : plumbing;;
765 merge-*) : plumbing;;
768 pack-objects) : plumbing;;
769 pack-redundant) : plumbing;;
770 pack-refs) : plumbing;;
771 parse-remote) : plumbing;;
772 patch-id) : plumbing;;
773 peek-remote) : plumbing;;
775 prune-packed) : plumbing;;
776 quiltimport) : import;;
777 read-tree) : plumbing;;
778 receive-pack) : plumbing;;
779 remote-*) : transport;;
780 repo-config) : deprecated;;
782 rev-list) : plumbing;;
783 rev-parse) : plumbing;;
784 runstatus) : plumbing;;
785 sh-setup) : internal;;
787 show-ref) : plumbing;;
788 send-pack) : plumbing;;
789 show-index) : plumbing;;
791 stripspace) : plumbing;;
792 symbolic-ref) : plumbing;;
793 tar-tree) : deprecated;;
794 unpack-file) : plumbing;;
795 unpack-objects) : plumbing;;
796 update-index) : plumbing;;
797 update-ref) : plumbing;;
798 update-server-info) : daemon;;
799 upload-archive) : plumbing;;
800 upload-pack) : plumbing;;
801 write-tree) : plumbing;;
803 verify-pack) : infrequent;;
804 verify-tag) : plumbing;;
810 __git_porcelain_commands=
811 __git_compute_porcelain_commands ()
813 __git_compute_all_commands
814 test -n "$__git_porcelain_commands" ||
815 __git_porcelain_commands=$(__git_list_porcelain_commands)
818 __git_pretty_aliases ()
821 for i in $(git --git-dir="$(__gitdir)" config --get-regexp "pretty\..*" 2>/dev/null); do
834 for i in $(git --git-dir="$(__gitdir)" config --get-regexp "alias\..*" 2>/dev/null); do
844 # __git_aliased_command requires 1 argument
845 __git_aliased_command ()
847 local word cmdline=$(git --git-dir="$(__gitdir)" \
848 config --get "alias.$1")
849 for word in $cmdline; do
855 \!*) : shell command alias ;;
857 *=*) : setting env ;;
866 # __git_find_on_cmdline requires 1 argument
867 __git_find_on_cmdline ()
869 local word subcommand c=1
870 while [ $c -lt $cword ]; do
872 for subcommand in $1; do
873 if [ "$subcommand" = "$word" ]; then
882 __git_has_doubledash ()
885 while [ $c -lt $cword ]; do
886 if [ "--" = "${words[c]}" ]; then
894 # Try to count non option arguments passed on the command line for the
895 # specified git command.
896 # When options are used, it is necessary to use the special -- option to
897 # tell the implementation were non option arguments begin.
898 # XXX this can not be improved, since options can appear everywhere, as
902 # __git_count_arguments requires 1 argument: the git command executed.
903 __git_count_arguments ()
907 # Skip "git" (first argument)
908 for ((i=1; i < ${#words[@]}; i++)); do
913 # Good; we can assume that the following are only non
918 # Skip the specified git command and discard git
931 __git_whitespacelist="nowarn warn error error-all fix"
935 local dir="$(__gitdir)"
936 if [ -d "$dir"/rebase-apply ]; then
937 __gitcomp "--skip --continue --resolved --abort"
942 __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
947 --3way --committer-date-is-author-date --ignore-date
948 --ignore-whitespace --ignore-space-change
949 --interactive --keep --no-utf8 --signoff --utf8
950 --whitespace= --scissors
961 __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
966 --stat --numstat --summary --check --index
967 --cached --index-info --reverse --reject --unidiff-zero
968 --apply --no-add --exclude=
969 --ignore-whitespace --ignore-space-change
970 --whitespace= --inaccurate-eof --verbose
982 --interactive --refresh --patch --update --dry-run
983 --ignore-errors --intent-to-add
988 # XXX should we check for --update and --all options ?
989 __git_complete_index_file "--others --modified"
996 __gitcomp "$(git archive --list)" "" "${cur##--format=}"
1000 __gitcomp_nl "$(__git_remotes)" "" "${cur##--remote=}"
1005 --format= --list --verbose
1006 --prefix= --remote= --exec=
1016 __git_has_doubledash && return
1018 local subcommands="start bad good skip reset visualize replay log run"
1019 local subcommand="$(__git_find_on_cmdline "$subcommands")"
1020 if [ -z "$subcommand" ]; then
1021 if [ -f "$(__gitdir)"/BISECT_START ]; then
1022 __gitcomp "$subcommands"
1024 __gitcomp "replay start"
1029 case "$subcommand" in
1030 bad|good|reset|skip|start)
1031 __gitcomp_nl "$(__git_refs)"
1041 local i c=1 only_local_ref="n" has_r="n"
1043 while [ $c -lt $cword ]; do
1046 -d|-m) only_local_ref="y" ;;
1053 --set-upstream-to=*)
1054 __gitcomp "$(__git_refs)" "" "${cur##--set-upstream-to=}"
1058 --color --no-color --verbose --abbrev= --no-abbrev
1059 --track --no-track --contains --merged --no-merged
1060 --set-upstream-to= --edit-description --list
1065 if [ $only_local_ref = "y" -a $has_r = "n" ]; then
1066 __gitcomp_nl "$(__git_heads)"
1068 __gitcomp_nl "$(__git_refs)"
1076 local cmd="${words[2]}"
1079 __gitcomp "create list-heads verify unbundle"
1082 # looking for a file
1087 __git_complete_revlist
1096 __git_has_doubledash && return
1100 __gitcomp "diff3 merge" "" "${cur##--conflict=}"
1104 --quiet --ours --theirs --track --no-track --merge
1105 --conflict= --orphan --patch
1109 # check if --track, --no-track, or --no-guess was specified
1110 # if so, disable DWIM mode
1111 local flags="--track --no-track --no-guess" track=1
1112 if [ -n "$(__git_find_on_cmdline "$flags")" ]; then
1115 __gitcomp_nl "$(__git_refs '' $track)"
1122 __gitcomp "$(__git_refs)"
1129 __gitcomp "--edit --no-commit"
1132 __gitcomp_nl "$(__git_refs)"
1141 __gitcomp "--dry-run --quiet"
1146 # XXX should we check for -x option ?
1147 __git_complete_index_file "--others"
1180 __gitcomp_nl "$(__git_refs)" "" "${cur}"
1187 __gitcomp_nl "$(__git_refs)" "" "${cur}"
1194 __gitcomp "default strip verbatim whitespace
1195 " "" "${cur##--cleanup=}"
1198 --reuse-message=*|--reedit-message=*|\
1199 --fixup=*|--squash=*)
1200 __gitcomp_nl "$(__git_refs)" "" "${cur#*=}"
1203 --untracked-files=*)
1204 __gitcomp "all no normal" "" "${cur##--untracked-files=}"
1209 --all --author= --signoff --verify --no-verify
1211 --amend --include --only --interactive
1212 --dry-run --reuse-message= --reedit-message=
1213 --reset-author --file= --message= --template=
1214 --cleanup= --untracked-files --untracked-files=
1215 --verbose --quiet --fixup= --squash=
1220 if git rev-parse --verify --quiet HEAD >/dev/null; then
1221 __git_complete_diff_index_file "HEAD"
1223 # This is the first commit
1224 __git_complete_index_file "--cached"
1233 --all --tags --contains --abbrev= --candidates=
1234 --exact-match --debug --long --match --always
1238 __gitcomp_nl "$(__git_refs)"
1241 __git_diff_algorithms="myers minimal patience histogram"
1243 __git_diff_common_options="--stat --numstat --shortstat --summary
1244 --patch-with-stat --name-only --name-status --color
1245 --no-color --color-words --no-renames --check
1246 --full-index --binary --abbrev --diff-filter=
1247 --find-copies-harder
1248 --text --ignore-space-at-eol --ignore-space-change
1249 --ignore-all-space --exit-code --quiet --ext-diff
1251 --no-prefix --src-prefix= --dst-prefix=
1252 --inter-hunk-context=
1253 --patience --histogram --minimal
1255 --dirstat --dirstat= --dirstat-by-file
1256 --dirstat-by-file= --cumulative
1262 __git_has_doubledash && return
1266 __gitcomp "$__git_diff_algorithms" "" "${cur##--diff-algorithm=}"
1270 __gitcomp "--cached --staged --pickaxe-all --pickaxe-regex
1271 --base --ours --theirs --no-index
1272 $__git_diff_common_options
1277 __git_complete_revlist_file
1280 __git_mergetools_common="diffuse ecmerge emerge kdiff3 meld opendiff
1281 tkdiff vimdiff gvimdiff xxdiff araxis p4merge bc3 codecompare
1286 __git_has_doubledash && return
1290 __gitcomp "$__git_mergetools_common kompare" "" "${cur##--tool=}"
1294 __gitcomp "--cached --staged --pickaxe-all --pickaxe-regex
1295 --base --ours --theirs
1296 --no-renames --diff-filter= --find-copies-harder
1297 --relative --ignore-submodules
1305 __git_fetch_options="
1306 --quiet --verbose --append --upload-pack --force --keep --depth=
1307 --tags --no-tags --all --prune --dry-run
1314 __gitcomp "$__git_fetch_options"
1318 __git_complete_remote_or_refspec
1321 __git_format_patch_options="
1322 --stdout --attach --no-attach --thread --thread= --output-directory
1323 --numbered --start-number --numbered-files --keep-subject --signoff
1324 --signature --no-signature --in-reply-to= --cc= --full-index --binary
1325 --not --all --cover-letter --no-prefix --src-prefix= --dst-prefix=
1326 --inline --suffix= --ignore-if-in-upstream --subject-prefix=
1329 _git_format_patch ()
1335 " "" "${cur##--thread=}"
1339 __gitcomp "$__git_format_patch_options"
1343 __git_complete_revlist
1351 --tags --root --unreachable --cache --no-reflogs --full
1352 --strict --verbose --lost-found
1364 __gitcomp "--prune --aggressive"
1376 __git_match_ctag() {
1377 awk "/^${1////\\/}/ { print \$1 }" "$2"
1382 __git_has_doubledash && return
1388 --text --ignore-case --word-regexp --invert-match
1389 --full-name --line-number
1390 --extended-regexp --basic-regexp --fixed-strings
1392 --files-with-matches --name-only
1393 --files-without-match
1396 --and --or --not --all-match
1402 case "$cword,$prev" in
1404 if test -r tags; then
1405 __gitcomp_nl "$(__git_match_ctag "$cur" tags)"
1411 __gitcomp_nl "$(__git_refs)"
1418 __gitcomp "--all --info --man --web"
1422 __git_compute_all_commands
1423 __gitcomp "$__git_all_commands $(__git_aliases)
1424 attributes cli core-tutorial cvs-migration
1425 diffcore gitk glossary hooks ignore modules
1426 namespaces repository-layout tutorial tutorial-2
1436 false true umask group all world everybody
1437 " "" "${cur##--shared=}"
1441 __gitcomp "--quiet --bare --template= --shared --shared="
1452 __gitcomp "--cached --deleted --modified --others --ignored
1453 --stage --directory --no-empty-directory --unmerged
1454 --killed --exclude= --exclude-from=
1455 --exclude-per-directory= --exclude-standard
1456 --error-unmatch --with-tree= --full-name
1457 --abbrev --ignored --exclude-per-directory
1463 # XXX ignore options like --modified and always suggest all cached
1465 __git_complete_index_file "--cached"
1470 __gitcomp_nl "$(__git_remotes)"
1478 # Options that go well for log, shortlog and gitk
1479 __git_log_common_options="
1481 --branches --tags --remotes
1482 --first-parent --merges --no-merges
1484 --max-age= --since= --after=
1485 --min-age= --until= --before=
1486 --min-parents= --max-parents=
1487 --no-min-parents --no-max-parents
1489 # Options that go well for log and gitk (not shortlog)
1490 __git_log_gitk_options="
1491 --dense --sparse --full-history
1492 --simplify-merges --simplify-by-decoration
1493 --left-right --notes --no-notes
1495 # Options that go well for log and shortlog (not gitk)
1496 __git_log_shortlog_options="
1497 --author= --committer= --grep=
1501 __git_log_pretty_formats="oneline short medium full fuller email raw format:"
1502 __git_log_date_formats="relative iso8601 rfc2822 short local default raw"
1506 __git_has_doubledash && return
1508 local g="$(git rev-parse --git-dir 2>/dev/null)"
1510 if [ -f "$g/MERGE_HEAD" ]; then
1514 --pretty=*|--format=*)
1515 __gitcomp "$__git_log_pretty_formats $(__git_pretty_aliases)
1520 __gitcomp "$__git_log_date_formats" "" "${cur##--date=}"
1524 __gitcomp "long short" "" "${cur##--decorate=}"
1529 $__git_log_common_options
1530 $__git_log_shortlog_options
1531 $__git_log_gitk_options
1532 --root --topo-order --date-order --reverse
1533 --follow --full-diff
1534 --abbrev-commit --abbrev=
1535 --relative-date --date=
1536 --pretty= --format= --oneline
1539 --decorate --decorate=
1541 --parents --children
1543 $__git_diff_common_options
1544 --pickaxe-all --pickaxe-regex
1549 __git_complete_revlist
1552 __git_merge_options="
1553 --no-commit --no-stat --log --no-log --squash --strategy
1554 --commit --stat --no-squash --ff --no-ff --ff-only --edit --no-edit
1559 __git_complete_strategy && return
1563 __gitcomp "$__git_merge_options"
1566 __gitcomp_nl "$(__git_refs)"
1573 __gitcomp "$__git_mergetools_common tortoisemerge" "" "${cur##--tool=}"
1586 __gitcomp_nl "$(__git_refs)"
1593 __gitcomp "--dry-run"
1598 if [ $(__git_count_arguments "mv") -gt 0 ]; then
1599 # We need to show both cached and untracked files (including
1600 # empty directories) since this may not be the last argument.
1601 __git_complete_index_file "--cached --others --directory"
1603 __git_complete_index_file "--cached"
1609 __gitcomp "--tags --all --stdin"
1614 local subcommands='add append copy edit list prune remove show'
1615 local subcommand="$(__git_find_on_cmdline "$subcommands")"
1617 case "$subcommand,$cur" in
1624 __gitcomp_nl "$(__git_refs)"
1627 __gitcomp "$subcommands --ref"
1631 add,--reuse-message=*|append,--reuse-message=*|\
1632 add,--reedit-message=*|append,--reedit-message=*)
1633 __gitcomp_nl "$(__git_refs)" "" "${cur#*=}"
1636 __gitcomp '--file= --message= --reedit-message=
1643 __gitcomp '--dry-run --verbose'
1652 __gitcomp_nl "$(__git_refs)"
1661 __git_complete_strategy && return
1666 --rebase --no-rebase
1667 $__git_merge_options
1668 $__git_fetch_options
1673 __git_complete_remote_or_refspec
1680 __gitcomp_nl "$(__git_remotes)"
1685 __gitcomp_nl "$(__git_remotes)" "" "${cur##--repo=}"
1690 --all --mirror --tags --dry-run --force --verbose
1691 --receive-pack= --repo= --set-upstream
1696 __git_complete_remote_or_refspec
1701 local dir="$(__gitdir)"
1702 if [ -d "$dir"/rebase-apply ] || [ -d "$dir"/rebase-merge ]; then
1703 __gitcomp "--continue --skip --abort"
1706 __git_complete_strategy && return
1709 __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
1714 --onto --merge --strategy --interactive
1715 --preserve-merges --stat --no-stat
1716 --committer-date-is-author-date --ignore-date
1717 --ignore-whitespace --whitespace=
1723 __gitcomp_nl "$(__git_refs)"
1728 local subcommands="show delete expire"
1729 local subcommand="$(__git_find_on_cmdline "$subcommands")"
1731 if [ -z "$subcommand" ]; then
1732 __gitcomp "$subcommands"
1734 __gitcomp_nl "$(__git_refs)"
1738 __git_send_email_confirm_options="always never auto cc compose"
1739 __git_send_email_suppresscc_options="author self cc bodycc sob cccmd body all"
1746 $__git_send_email_confirm_options
1747 " "" "${cur##--confirm=}"
1752 $__git_send_email_suppresscc_options
1753 " "" "${cur##--suppress-cc=}"
1757 --smtp-encryption=*)
1758 __gitcomp "ssl tls" "" "${cur##--smtp-encryption=}"
1764 " "" "${cur##--thread=}"
1768 __gitcomp "--annotate --bcc --cc --cc-cmd --chain-reply-to
1769 --compose --confirm= --dry-run --envelope-sender
1771 --in-reply-to --no-chain-reply-to --no-signed-off-by-cc
1772 --no-suppress-from --no-thread --quiet
1773 --signed-off-by-cc --smtp-pass --smtp-server
1774 --smtp-server-port --smtp-encryption= --smtp-user
1775 --subject --suppress-cc= --suppress-from --thread --to
1776 --validate --no-validate
1777 $__git_format_patch_options"
1781 __git_complete_revlist
1789 __git_config_get_set_variables ()
1791 local prevword word config_file= c=$cword
1792 while [ $c -gt 1 ]; do
1795 --system|--global|--local|--file=*)
1800 config_file="$word $prevword"
1808 git --git-dir="$(__gitdir)" config $config_file --list 2>/dev/null |
1823 __gitcomp_nl "$(__git_remotes)"
1827 __gitcomp_nl "$(__git_refs)"
1831 local remote="${prev#remote.}"
1832 remote="${remote%.fetch}"
1833 if [ -z "$cur" ]; then
1834 COMPREPLY=("refs/heads/")
1837 __gitcomp_nl "$(__git_refs_remotes "$remote")"
1841 local remote="${prev#remote.}"
1842 remote="${remote%.push}"
1843 __gitcomp_nl "$(git --git-dir="$(__gitdir)" \
1844 for-each-ref --format='%(refname):%(refname)' \
1848 pull.twohead|pull.octopus)
1849 __git_compute_merge_strategies
1850 __gitcomp "$__git_merge_strategies"
1853 color.branch|color.diff|color.interactive|\
1854 color.showbranch|color.status|color.ui)
1855 __gitcomp "always never auto"
1859 __gitcomp "false true"
1864 normal black red green yellow blue magenta cyan white
1865 bold dim ul blink reverse
1870 __gitcomp "man info web html"
1874 __gitcomp "$__git_log_date_formats"
1877 sendemail.aliasesfiletype)
1878 __gitcomp "mutt mailrc pine elm gnus"
1882 __gitcomp "$__git_send_email_confirm_options"
1885 sendemail.suppresscc)
1886 __gitcomp "$__git_send_email_suppresscc_options"
1889 --get|--get-all|--unset|--unset-all)
1890 __gitcomp_nl "$(__git_config_get_set_variables)"
1901 --system --global --local --file=
1902 --list --replace-all
1903 --get --get-all --get-regexp
1904 --add --unset --unset-all
1905 --remove-section --rename-section
1910 local pfx="${cur%.*}." cur_="${cur##*.}"
1911 __gitcomp "remote merge mergeoptions rebase" "$pfx" "$cur_"
1915 local pfx="${cur%.*}." cur_="${cur#*.}"
1916 __gitcomp_nl "$(__git_heads)" "$pfx" "$cur_" "."
1920 local pfx="${cur%.*}." cur_="${cur##*.}"
1922 argprompt cmd confirm needsfile noconsole norescan
1923 prompt revprompt revunmerged title
1928 local pfx="${cur%.*}." cur_="${cur##*.}"
1929 __gitcomp "cmd path" "$pfx" "$cur_"
1933 local pfx="${cur%.*}." cur_="${cur##*.}"
1934 __gitcomp "cmd path" "$pfx" "$cur_"
1938 local pfx="${cur%.*}." cur_="${cur##*.}"
1939 __gitcomp "cmd path trustExitCode" "$pfx" "$cur_"
1943 local pfx="${cur%.*}." cur_="${cur#*.}"
1944 __git_compute_all_commands
1945 __gitcomp_nl "$__git_all_commands" "$pfx" "$cur_"
1949 local pfx="${cur%.*}." cur_="${cur##*.}"
1951 url proxy fetch push mirror skipDefaultUpdate
1952 receivepack uploadpack tagopt pushurl
1957 local pfx="${cur%.*}." cur_="${cur#*.}"
1958 __gitcomp_nl "$(__git_remotes)" "$pfx" "$cur_" "."
1962 local pfx="${cur%.*}." cur_="${cur##*.}"
1963 __gitcomp "insteadOf pushInsteadOf" "$pfx" "$cur_"
1969 advice.commitBeforeMerge
1971 advice.implicitIdentity
1972 advice.pushNonFastForward
1973 advice.resolveConflict
1977 apply.ignorewhitespace
1979 branch.autosetupmerge
1980 branch.autosetuprebase
1984 color.branch.current
1989 color.decorate.branch
1990 color.decorate.remoteBranch
1991 color.decorate.stash
2001 color.diff.whitespace
2006 color.grep.linenumber
2009 color.grep.separator
2011 color.interactive.error
2012 color.interactive.header
2013 color.interactive.help
2014 color.interactive.prompt
2019 color.status.changed
2021 color.status.nobranch
2022 color.status.untracked
2023 color.status.updated
2032 core.bigFileThreshold
2035 core.deltaBaseCacheLimit
2040 core.fsyncobjectfiles
2042 core.ignoreCygwinFSTricks
2045 core.logAllRefUpdates
2046 core.loosecompression
2049 core.packedGitWindowSize
2051 core.preferSymlinkRefs
2054 core.repositoryFormatVersion
2056 core.sharedRepository
2060 core.warnAmbiguousRefs
2063 diff.autorefreshindex
2066 diff.ignoreSubmodules
2071 diff.suppressBlankEmpty
2077 fetch.recurseSubmodules
2086 format.subjectprefix
2097 gc.reflogexpireunreachable
2101 gitcvs.commitmsgannotation
2102 gitcvs.dbTableNamePrefix
2113 gui.copyblamethreshold
2117 gui.matchtrackingbranch
2118 gui.newbranchtemplate
2119 gui.pruneduringfetch
2120 gui.spellingdictionary
2135 http.sslCertPasswordProtected
2140 i18n.logOutputEncoding
2146 imap.preformattedHTML
2156 interactive.singlekey
2172 mergetool.keepBackup
2173 mergetool.keepTemporaries
2178 notes.rewrite.rebase
2182 pack.deltaCacheLimit
2198 receive.denyCurrentBranch
2199 receive.denyDeleteCurrent
2201 receive.denyNonFastForwards
2204 receive.updateserverinfo
2206 repack.usedeltabaseoffset
2210 sendemail.aliasesfile
2211 sendemail.aliasfiletype
2215 sendemail.chainreplyto
2217 sendemail.envelopesender
2221 sendemail.signedoffbycc
2222 sendemail.smtpdomain
2223 sendemail.smtpencryption
2225 sendemail.smtpserver
2226 sendemail.smtpserveroption
2227 sendemail.smtpserverport
2229 sendemail.suppresscc
2230 sendemail.suppressfrom
2235 status.relativePaths
2236 status.showUntrackedFiles
2237 status.submodulesummary
2240 transfer.unpackLimit
2252 local subcommands="add rename remove set-head set-branches set-url show prune update"
2253 local subcommand="$(__git_find_on_cmdline "$subcommands")"
2254 if [ -z "$subcommand" ]; then
2255 __gitcomp "$subcommands"
2259 case "$subcommand" in
2260 rename|remove|set-url|show|prune)
2261 __gitcomp_nl "$(__git_remotes)"
2263 set-head|set-branches)
2264 __git_complete_remote_or_refspec
2267 local i c='' IFS=$'\n'
2268 for i in $(git --git-dir="$(__gitdir)" config --get-regexp "remotes\..*" 2>/dev/null); do
2282 __gitcomp_nl "$(__git_refs)"
2287 __git_has_doubledash && return
2291 __gitcomp "--merge --mixed --hard --soft --patch"
2295 __gitcomp_nl "$(__git_refs)"
2302 __gitcomp "--edit --mainline --no-edit --no-commit --signoff"
2306 __gitcomp_nl "$(__git_refs)"
2313 __gitcomp "--cached --dry-run --ignore-unmatch --quiet"
2318 __git_complete_index_file "--cached"
2323 __git_has_doubledash && return
2328 $__git_log_common_options
2329 $__git_log_shortlog_options
2330 --numbered --summary
2335 __git_complete_revlist
2340 __git_has_doubledash && return
2343 --pretty=*|--format=*)
2344 __gitcomp "$__git_log_pretty_formats $(__git_pretty_aliases)
2349 __gitcomp "$__git_diff_algorithms" "" "${cur##--diff-algorithm=}"
2353 __gitcomp "--pretty= --format= --abbrev-commit --oneline
2354 $__git_diff_common_options
2367 --all --remotes --topo-order --current --more=
2368 --list --independent --merge-base --no-name
2370 --sha1-name --sparse --topics --reflog
2375 __git_complete_revlist
2380 local save_opts='--keep-index --no-keep-index --quiet --patch'
2381 local subcommands='save list show apply clear drop pop create branch'
2382 local subcommand="$(__git_find_on_cmdline "$subcommands")"
2383 if [ -z "$subcommand" ]; then
2386 __gitcomp "$save_opts"
2389 if [ -z "$(__git_find_on_cmdline "$save_opts")" ]; then
2390 __gitcomp "$subcommands"
2397 case "$subcommand,$cur" in
2399 __gitcomp "$save_opts"
2402 __gitcomp "--index --quiet"
2404 show,--*|drop,--*|branch,--*)
2407 show,*|apply,*|drop,*|pop,*|branch,*)
2408 __gitcomp_nl "$(git --git-dir="$(__gitdir)" stash list \
2409 | sed -n -e 's/:.*//p')"
2420 __git_has_doubledash && return
2422 local subcommands="add status init update summary foreach sync"
2423 if [ -z "$(__git_find_on_cmdline "$subcommands")" ]; then
2426 __gitcomp "--quiet --cached"
2429 __gitcomp "$subcommands"
2439 init fetch clone rebase dcommit log find-rev
2440 set-tree commit-diff info create-ignore propget
2441 proplist show-ignore show-externals branch tag blame
2442 migrate mkdirs reset gc
2444 local subcommand="$(__git_find_on_cmdline "$subcommands")"
2445 if [ -z "$subcommand" ]; then
2446 __gitcomp "$subcommands"
2448 local remote_opts="--username= --config-dir= --no-auth-cache"
2450 --follow-parent --authors-file= --repack=
2451 --no-metadata --use-svm-props --use-svnsync-props
2452 --log-window-size= --no-checkout --quiet
2453 --repack-flags --use-log-author --localtime
2454 --ignore-paths= $remote_opts
2457 --template= --shared= --trunk= --tags=
2458 --branches= --stdlayout --minimize-url
2459 --no-metadata --use-svm-props --use-svnsync-props
2460 --rewrite-root= --prefix= --use-log-author
2461 --add-author-from $remote_opts
2464 --edit --rmdir --find-copies-harder --copy-similarity=
2467 case "$subcommand,$cur" in
2469 __gitcomp "--revision= --fetch-all $fc_opts"
2472 __gitcomp "--revision= $fc_opts $init_opts"
2475 __gitcomp "$init_opts"
2479 --merge --strategy= --verbose --dry-run
2480 --fetch-all --no-rebase --commit-url
2481 --revision --interactive $cmt_opts $fc_opts
2485 __gitcomp "--stdin $cmt_opts $fc_opts"
2487 create-ignore,--*|propget,--*|proplist,--*|show-ignore,--*|\
2488 show-externals,--*|mkdirs,--*)
2489 __gitcomp "--revision="
2493 --limit= --revision= --verbose --incremental
2494 --oneline --show-commit --non-recursive
2495 --authors-file= --color
2500 --merge --verbose --strategy= --local
2501 --fetch-all --dry-run $fc_opts
2505 __gitcomp "--message= --file= --revision= $cmt_opts"
2511 __gitcomp "--dry-run --message --tag"
2514 __gitcomp "--dry-run --message"
2517 __gitcomp "--git-format"
2521 --config-dir= --ignore-paths= --minimize
2522 --no-auth-cache --username=
2526 __gitcomp "--revision= --parent"
2538 while [ $c -lt $cword ]; do
2542 __gitcomp_nl "$(__git_tags)"
2558 __gitcomp_nl "$(__git_tags)"
2564 __gitcomp_nl "$(__git_refs)"
2576 local i c=1 command __git_dir
2578 while [ $c -lt $cword ]; do
2581 --git-dir=*) __git_dir="${i#--git-dir=}" ;;
2582 --bare) __git_dir="." ;;
2583 --help) command="help"; break ;;
2586 *) command="$i"; break ;;
2591 if [ -z "$command" ]; then
2605 --no-replace-objects
2609 *) __git_compute_porcelain_commands
2610 __gitcomp "$__git_porcelain_commands $(__git_aliases)" ;;
2615 local completion_func="_git_${command//-/_}"
2616 declare -f $completion_func >/dev/null && $completion_func && return
2618 local expansion=$(__git_aliased_command "$command")
2619 if [ -n "$expansion" ]; then
2620 completion_func="_git_${expansion//-/_}"
2621 declare -f $completion_func >/dev/null && $completion_func
2627 __git_has_doubledash && return
2629 local g="$(__gitdir)"
2631 if [ -f "$g/MERGE_HEAD" ]; then
2637 $__git_log_common_options
2638 $__git_log_gitk_options
2644 __git_complete_revlist
2647 if [[ -n ${ZSH_VERSION-} ]]; then
2648 echo "WARNING: this script is deprecated, please see git-completion.zsh" 1>&2
2650 autoload -U +X compinit && compinit
2656 local cur_="${3-$cur}"
2662 local c IFS=$' \t\n'
2670 array[$#array+1]="$c"
2673 compadd -Q -S '' -p "${2-}" -a -- array && _ret=0
2684 compadd -Q -S "${4- }" -p "${2-}" -- ${=1} && _ret=0
2693 compadd -Q -p "${2-}" -f -- ${=1} && _ret=0
2699 local cur cword prev
2700 cur=${words[CURRENT-1]}
2701 prev=${words[CURRENT-2]}
2711 let _ret && _default -S '' && _ret=0
2715 compdef _git git gitk
2717 elif [[ -n ${BASH_VERSION-} ]]; then
2718 if ((${BASH_VERSINFO[0]} < 4)); then
2719 # compopt is not supported
2720 __git_index_file_list_filter ()
2722 __git_index_file_list_filter_compat
2729 local cur words cword prev
2730 _get_comp_words_by_ref -n =: cur words cword prev
2734 # Setup completion for certain functions defined above by setting common
2735 # variables and workarounds.
2736 # This is NOT a public function; use at your own risk.
2739 local wrapper="__git_wrap${2}"
2740 eval "$wrapper () { __git_func_wrap $2 ; }"
2741 complete -o bashdefault -o default -o nospace -F $wrapper $1 2>/dev/null \
2742 || complete -o default -o nospace -F $wrapper $1
2745 # wrapper for backwards compatibility
2748 __git_wrap__git_main
2751 # wrapper for backwards compatibility
2754 __git_wrap__gitk_main
2757 __git_complete git __git_main
2758 __git_complete gitk __gitk_main
2760 # The following are necessary only for Cygwin, and only are needed
2761 # when the user has tab-completed the executable name and consequently
2762 # included the '.exe' suffix.
2764 if [ Cygwin = "$(uname -o 2>/dev/null)" ]; then
2765 __git_complete git.exe __git_main