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 # *) common --long-options
18 # To use these routines:
20 # 1) Copy this file to somewhere (e.g. ~/.git-completion.sh).
21 # 2) Add the following line to your .bashrc/.zshrc:
22 # source ~/.git-completion.sh
23 # 3) Consider changing your PS1 to also show the current branch,
24 # see git-prompt.sh for details.
26 if [[ -n ${ZSH_VERSION-} ]]; then
27 autoload -U +X bashcompinit && bashcompinit
30 case "$COMP_WORDBREAKS" in
32 *) COMP_WORDBREAKS="$COMP_WORDBREAKS:"
35 # __gitdir accepts 0 or 1 arguments (i.e., location)
36 # returns location of .git repo
39 # Note: this function is duplicated in git-prompt.sh
40 # When updating it, make sure you update the other one to match.
41 if [ -z "${1-}" ]; then
42 if [ -n "${__git_dir-}" ]; then
44 elif [ -n "${GIT_DIR-}" ]; then
45 test -d "${GIT_DIR-}" || return 1
47 elif [ -d .git ]; then
50 git rev-parse --git-dir 2>/dev/null
52 elif [ -d "$1/.git" ]; then
72 # The following function is based on code from:
74 # bash_completion - programmable completion functions for bash 3.2+
76 # Copyright © 2006-2008, Ian Macdonald <ian@caliban.org>
77 # © 2009-2010, Bash Completion Maintainers
78 # <bash-completion-devel@lists.alioth.debian.org>
80 # This program is free software; you can redistribute it and/or modify
81 # it under the terms of the GNU General Public License as published by
82 # the Free Software Foundation; either version 2, or (at your option)
85 # This program is distributed in the hope that it will be useful,
86 # but WITHOUT ANY WARRANTY; without even the implied warranty of
87 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
88 # GNU General Public License for more details.
90 # You should have received a copy of the GNU General Public License
91 # along with this program; if not, write to the Free Software Foundation,
92 # Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
94 # The latest version of this software can be obtained here:
96 # http://bash-completion.alioth.debian.org/
100 # This function can be used to access a tokenized list of words
101 # on the command line:
103 # __git_reassemble_comp_words_by_ref '=:'
104 # if test "${words_[cword_-1]}" = -w
109 # The argument should be a collection of characters from the list of
110 # word completion separators (COMP_WORDBREAKS) to treat as ordinary
113 # This is roughly equivalent to going back in time and setting
114 # COMP_WORDBREAKS to exclude those characters. The intent is to
115 # make option types like --date=<type> and <rev>:<path> easy to
116 # recognize by treating each shell word as a single token.
118 # It is best not to set COMP_WORDBREAKS directly because the value is
119 # shared with other completion scripts. By the time the completion
120 # function gets called, COMP_WORDS has already been populated so local
121 # changes to COMP_WORDBREAKS have no effect.
123 # Output: words_, cword_, cur_.
125 __git_reassemble_comp_words_by_ref()
127 local exclude i j first
128 # Which word separators to exclude?
129 exclude="${1//[^$COMP_WORDBREAKS]}"
131 if [ -z "$exclude" ]; then
132 words_=("${COMP_WORDS[@]}")
135 # List of word completion separators has shrunk;
136 # re-assemble words to complete.
137 for ((i=0, j=0; i < ${#COMP_WORDS[@]}; i++, j++)); do
138 # Append each nonempty word consisting of just
139 # word separator characters to the current word.
143 [ -n "${COMP_WORDS[$i]}" ] &&
144 # word consists of excluded word separators
145 [ "${COMP_WORDS[$i]//[^$exclude]}" = "${COMP_WORDS[$i]}" ]
147 # Attach to the previous token,
148 # unless the previous token is the command name.
149 if [ $j -ge 2 ] && [ -n "$first" ]; then
153 words_[$j]=${words_[j]}${COMP_WORDS[i]}
154 if [ $i = $COMP_CWORD ]; then
157 if (($i < ${#COMP_WORDS[@]} - 1)); then
164 words_[$j]=${words_[j]}${COMP_WORDS[i]}
165 if [ $i = $COMP_CWORD ]; then
171 if ! type _get_comp_words_by_ref >/dev/null 2>&1; then
172 if [[ -z ${ZSH_VERSION:+set} ]]; then
173 _get_comp_words_by_ref ()
175 local exclude cur_ words_ cword_
176 if [ "$1" = "-n" ]; then
180 __git_reassemble_comp_words_by_ref "$exclude"
181 cur_=${words_[cword_]}
182 while [ $# -gt 0 ]; do
188 prev=${words_[$cword_-1]}
191 words=("${words_[@]}")
201 _get_comp_words_by_ref ()
203 while [ $# -gt 0 ]; do
206 cur=${COMP_WORDS[COMP_CWORD]}
209 prev=${COMP_WORDS[COMP_CWORD-1]}
212 words=("${COMP_WORDS[@]}")
218 # assume COMP_WORDBREAKS is already set sanely
228 # Quotes the argument for shell reuse
231 local quoted=${1//\'/\'\\\'\'}
232 printf "'%s'" "$quoted"
235 # Generates completion reply with compgen, appending a space to possible
236 # completion words, if necessary.
237 # It accepts 1 to 4 arguments:
238 # 1: List of possible completion words.
239 # 2: A prefix to be added to each possible completion word (optional).
240 # 3: Generate possible completion matches for this word (optional).
241 # 4: A suffix to be appended to each possible completion word (optional).
244 local cur_="${3-$cur}"
252 COMPREPLY=($(compgen -P "${2-}" \
253 -W "$(__gitcomp_1 "${1-}" "${4-}")" \
259 # Generates completion reply with compgen from newline-separated possible
260 # completion words by appending a space to all of them.
261 # It accepts 1 to 4 arguments:
262 # 1: List of possible completion words, separated by a single newline.
263 # 2: A prefix to be added to each possible completion word (optional).
264 # 3: Generate possible completion matches for this word (optional).
265 # 4: A suffix to be appended to each possible completion word instead of
266 # the default space (optional). If specified but empty, nothing is
271 COMPREPLY=($(compgen -P "${2-}" -S "${4- }" -W "$(__git_quote "$1")" -- "${3-$cur}"))
276 local dir="$(__gitdir)"
277 if [ -d "$dir" ]; then
278 git --git-dir="$dir" for-each-ref --format='%(refname:short)' \
286 local dir="$(__gitdir)"
287 if [ -d "$dir" ]; then
288 git --git-dir="$dir" for-each-ref --format='%(refname:short)' \
294 # __git_refs accepts 0, 1 (to pass to __gitdir), or 2 arguments
295 # presence of 2nd argument means use the guess heuristic employed
296 # by checkout for tracking branches
299 local i hash dir="$(__gitdir "${1-}")" track="${2-}"
301 if [ -d "$dir" ]; then
309 for i in HEAD FETCH_HEAD ORIG_HEAD MERGE_HEAD; do
310 if [ -e "$dir/$i" ]; then echo $i; fi
312 format="refname:short"
313 refs="refs/tags refs/heads refs/remotes"
316 git --git-dir="$dir" for-each-ref --format="%($format)" \
318 if [ -n "$track" ]; then
319 # employ the heuristic used by git checkout
320 # Try to find a remote branch that matches the completion word
321 # but only output if the branch name is unique
323 git --git-dir="$dir" for-each-ref --shell --format="ref=%(refname:short)" \
325 while read -r entry; do
328 if [[ "$ref" == "$cur"* ]]; then
337 git ls-remote "$dir" "$cur*" 2>/dev/null | \
338 while read -r hash i; do
346 git ls-remote "$dir" HEAD ORIG_HEAD 'refs/tags/*' 'refs/heads/*' 'refs/remotes/*' 2>/dev/null | \
347 while read -r hash i; do
350 refs/*) echo "${i#refs/*/}" ;;
358 # __git_refs2 requires 1 argument (to pass to __git_refs)
362 for i in $(__git_refs "$1"); do
367 # __git_refs_remotes requires 1 argument (to pass to ls-remote)
368 __git_refs_remotes ()
371 git ls-remote "$1" 'refs/heads/*' 2>/dev/null | \
372 while read -r hash i; do
373 echo "$i:refs/remotes/$1/${i#refs/heads/}"
379 local i IFS=$'\n' d="$(__gitdir)"
380 test -d "$d/remotes" && ls -1 "$d/remotes"
381 for i in $(git --git-dir="$d" config --get-regexp 'remote\..*\.url' 2>/dev/null); do
387 __git_list_merge_strategies ()
389 git merge -s help 2>&1 |
390 sed -n -e '/[Aa]vailable strategies are: /,/^$/{
399 __git_merge_strategies=
400 # 'git merge -s help' (and thus detection of the merge strategy
401 # list) fails, unfortunately, if run outside of any git working
402 # tree. __git_merge_strategies is set to the empty string in
403 # that case, and the detection will be repeated the next time it
405 __git_compute_merge_strategies ()
407 test -n "$__git_merge_strategies" ||
408 __git_merge_strategies=$(__git_list_merge_strategies)
411 __git_complete_revlist_file ()
413 local pfx ls ref cur_="$cur"
433 case "$COMP_WORDBREAKS" in
435 *) pfx="$ref:$pfx" ;;
438 __gitcomp_nl "$(git --git-dir="$(__gitdir)" ls-tree "$ls" \
439 | sed '/^100... blob /{
455 pfx="${cur_%...*}..."
457 __gitcomp_nl "$(__git_refs)" "$pfx" "$cur_"
462 __gitcomp_nl "$(__git_refs)" "$pfx" "$cur_"
465 __gitcomp_nl "$(__git_refs)"
471 __git_complete_file ()
473 __git_complete_revlist_file
476 __git_complete_revlist ()
478 __git_complete_revlist_file
481 __git_complete_remote_or_refspec ()
483 local cur_="$cur" cmd="${words[1]}"
484 local i c=2 remote="" pfx="" lhs=1 no_complete_refspec=0
485 if [ "$cmd" = "remote" ]; then
488 while [ $c -lt $cword ]; do
491 --mirror) [ "$cmd" = "push" ] && no_complete_refspec=1 ;;
494 push) no_complete_refspec=1 ;;
503 *) remote="$i"; break ;;
507 if [ -z "$remote" ]; then
508 __gitcomp_nl "$(__git_remotes)"
511 if [ $no_complete_refspec = 1 ]; then
515 [ "$remote" = "." ] && remote=
518 case "$COMP_WORDBREAKS" in
520 *) pfx="${cur_%%:*}:" ;;
532 if [ $lhs = 1 ]; then
533 __gitcomp_nl "$(__git_refs2 "$remote")" "$pfx" "$cur_"
535 __gitcomp_nl "$(__git_refs)" "$pfx" "$cur_"
539 if [ $lhs = 1 ]; then
540 __gitcomp_nl "$(__git_refs "$remote")" "$pfx" "$cur_"
542 __gitcomp_nl "$(__git_refs)" "$pfx" "$cur_"
546 if [ $lhs = 1 ]; then
547 __gitcomp_nl "$(__git_refs)" "$pfx" "$cur_"
549 __gitcomp_nl "$(__git_refs "$remote")" "$pfx" "$cur_"
555 __git_complete_strategy ()
557 __git_compute_merge_strategies
560 __gitcomp "$__git_merge_strategies"
565 __gitcomp "$__git_merge_strategies" "" "${cur##--strategy=}"
572 __git_list_all_commands ()
575 for i in $(git help -a|egrep '^ [a-zA-Z0-9]')
578 *--*) : helper pattern;;
585 __git_compute_all_commands ()
587 test -n "$__git_all_commands" ||
588 __git_all_commands=$(__git_list_all_commands)
591 __git_list_porcelain_commands ()
594 __git_compute_all_commands
595 for i in "help" $__git_all_commands
598 *--*) : helper pattern;;
599 applymbox) : ask gittus;;
600 applypatch) : ask gittus;;
601 archimport) : import;;
602 cat-file) : plumbing;;
603 check-attr) : plumbing;;
604 check-ref-format) : plumbing;;
605 checkout-index) : plumbing;;
606 commit-tree) : plumbing;;
607 count-objects) : infrequent;;
608 credential-cache) : credentials helper;;
609 credential-store) : credentials helper;;
610 cvsexportcommit) : export;;
611 cvsimport) : import;;
612 cvsserver) : daemon;;
614 diff-files) : plumbing;;
615 diff-index) : plumbing;;
616 diff-tree) : plumbing;;
617 fast-import) : import;;
618 fast-export) : export;;
619 fsck-objects) : plumbing;;
620 fetch-pack) : plumbing;;
621 fmt-merge-msg) : plumbing;;
622 for-each-ref) : plumbing;;
623 hash-object) : plumbing;;
624 http-*) : transport;;
625 index-pack) : plumbing;;
626 init-db) : deprecated;;
627 local-fetch) : plumbing;;
628 lost-found) : infrequent;;
629 ls-files) : plumbing;;
630 ls-remote) : plumbing;;
631 ls-tree) : plumbing;;
632 mailinfo) : plumbing;;
633 mailsplit) : plumbing;;
634 merge-*) : plumbing;;
637 pack-objects) : plumbing;;
638 pack-redundant) : plumbing;;
639 pack-refs) : plumbing;;
640 parse-remote) : plumbing;;
641 patch-id) : plumbing;;
642 peek-remote) : plumbing;;
644 prune-packed) : plumbing;;
645 quiltimport) : import;;
646 read-tree) : plumbing;;
647 receive-pack) : plumbing;;
648 remote-*) : transport;;
649 repo-config) : deprecated;;
651 rev-list) : plumbing;;
652 rev-parse) : plumbing;;
653 runstatus) : plumbing;;
654 sh-setup) : internal;;
656 show-ref) : plumbing;;
657 send-pack) : plumbing;;
658 show-index) : plumbing;;
660 stripspace) : plumbing;;
661 symbolic-ref) : plumbing;;
662 tar-tree) : deprecated;;
663 unpack-file) : plumbing;;
664 unpack-objects) : plumbing;;
665 update-index) : plumbing;;
666 update-ref) : plumbing;;
667 update-server-info) : daemon;;
668 upload-archive) : plumbing;;
669 upload-pack) : plumbing;;
670 write-tree) : plumbing;;
672 verify-pack) : infrequent;;
673 verify-tag) : plumbing;;
679 __git_porcelain_commands=
680 __git_compute_porcelain_commands ()
682 __git_compute_all_commands
683 test -n "$__git_porcelain_commands" ||
684 __git_porcelain_commands=$(__git_list_porcelain_commands)
687 __git_pretty_aliases ()
690 for i in $(git --git-dir="$(__gitdir)" config --get-regexp "pretty\..*" 2>/dev/null); do
703 for i in $(git --git-dir="$(__gitdir)" config --get-regexp "alias\..*" 2>/dev/null); do
713 # __git_aliased_command requires 1 argument
714 __git_aliased_command ()
716 local word cmdline=$(git --git-dir="$(__gitdir)" \
717 config --get "alias.$1")
718 for word in $cmdline; do
724 \!*) : shell command alias ;;
726 *=*) : setting env ;;
735 # __git_find_on_cmdline requires 1 argument
736 __git_find_on_cmdline ()
738 local word subcommand c=1
739 while [ $c -lt $cword ]; do
741 for subcommand in $1; do
742 if [ "$subcommand" = "$word" ]; then
751 __git_has_doubledash ()
754 while [ $c -lt $cword ]; do
755 if [ "--" = "${words[c]}" ]; then
763 __git_whitespacelist="nowarn warn error error-all fix"
767 local dir="$(__gitdir)"
768 if [ -d "$dir"/rebase-apply ]; then
769 __gitcomp "--skip --continue --resolved --abort"
774 __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
779 --3way --committer-date-is-author-date --ignore-date
780 --ignore-whitespace --ignore-space-change
781 --interactive --keep --no-utf8 --signoff --utf8
782 --whitespace= --scissors
793 __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
798 --stat --numstat --summary --check --index
799 --cached --index-info --reverse --reject --unidiff-zero
800 --apply --no-add --exclude=
801 --ignore-whitespace --ignore-space-change
802 --whitespace= --inaccurate-eof --verbose
811 __git_has_doubledash && return
816 --interactive --refresh --patch --update --dry-run
817 --ignore-errors --intent-to-add
828 __gitcomp "$(git archive --list)" "" "${cur##--format=}"
832 __gitcomp_nl "$(__git_remotes)" "" "${cur##--remote=}"
837 --format= --list --verbose
838 --prefix= --remote= --exec=
848 __git_has_doubledash && return
850 local subcommands="start bad good skip reset visualize replay log run"
851 local subcommand="$(__git_find_on_cmdline "$subcommands")"
852 if [ -z "$subcommand" ]; then
853 if [ -f "$(__gitdir)"/BISECT_START ]; then
854 __gitcomp "$subcommands"
856 __gitcomp "replay start"
861 case "$subcommand" in
862 bad|good|reset|skip|start)
863 __gitcomp_nl "$(__git_refs)"
873 local i c=1 only_local_ref="n" has_r="n"
875 while [ $c -lt $cword ]; do
878 -d|-m) only_local_ref="y" ;;
887 --color --no-color --verbose --abbrev= --no-abbrev
888 --track --no-track --contains --merged --no-merged
889 --set-upstream --edit-description --list
893 if [ $only_local_ref = "y" -a $has_r = "n" ]; then
894 __gitcomp_nl "$(__git_heads)"
896 __gitcomp_nl "$(__git_refs)"
904 local cmd="${words[2]}"
907 __gitcomp "create list-heads verify unbundle"
915 __git_complete_revlist
924 __git_has_doubledash && return
928 __gitcomp "diff3 merge" "" "${cur##--conflict=}"
932 --quiet --ours --theirs --track --no-track --merge
933 --conflict= --orphan --patch
937 # check if --track, --no-track, or --no-guess was specified
938 # if so, disable DWIM mode
939 local flags="--track --no-track --no-guess" track=1
940 if [ -n "$(__git_find_on_cmdline "$flags")" ]; then
943 __gitcomp_nl "$(__git_refs '' $track)"
950 __gitcomp "$(__git_refs)"
957 __gitcomp "--edit --no-commit"
960 __gitcomp_nl "$(__git_refs)"
967 __git_has_doubledash && return
971 __gitcomp "--dry-run --quiet"
1004 __git_has_doubledash && return
1008 __gitcomp "default strip verbatim whitespace
1009 " "" "${cur##--cleanup=}"
1012 --reuse-message=*|--reedit-message=*|\
1013 --fixup=*|--squash=*)
1014 __gitcomp_nl "$(__git_refs)" "" "${cur#*=}"
1017 --untracked-files=*)
1018 __gitcomp "all no normal" "" "${cur##--untracked-files=}"
1023 --all --author= --signoff --verify --no-verify
1025 --amend --include --only --interactive
1026 --dry-run --reuse-message= --reedit-message=
1027 --reset-author --file= --message= --template=
1028 --cleanup= --untracked-files --untracked-files=
1029 --verbose --quiet --fixup= --squash=
1041 --all --tags --contains --abbrev= --candidates=
1042 --exact-match --debug --long --match --always
1046 __gitcomp_nl "$(__git_refs)"
1049 __git_diff_common_options="--stat --numstat --shortstat --summary
1050 --patch-with-stat --name-only --name-status --color
1051 --no-color --color-words --no-renames --check
1052 --full-index --binary --abbrev --diff-filter=
1053 --find-copies-harder
1054 --text --ignore-space-at-eol --ignore-space-change
1055 --ignore-all-space --exit-code --quiet --ext-diff
1057 --no-prefix --src-prefix= --dst-prefix=
1058 --inter-hunk-context=
1061 --dirstat --dirstat= --dirstat-by-file
1062 --dirstat-by-file= --cumulative
1067 __git_has_doubledash && return
1071 __gitcomp "--cached --staged --pickaxe-all --pickaxe-regex
1072 --base --ours --theirs --no-index
1073 $__git_diff_common_options
1078 __git_complete_revlist_file
1081 __git_mergetools_common="diffuse ecmerge emerge kdiff3 meld opendiff
1082 tkdiff vimdiff gvimdiff xxdiff araxis p4merge bc3
1087 __git_has_doubledash && return
1091 __gitcomp "$__git_mergetools_common kompare" "" "${cur##--tool=}"
1095 __gitcomp "--cached --staged --pickaxe-all --pickaxe-regex
1096 --base --ours --theirs
1097 --no-renames --diff-filter= --find-copies-harder
1098 --relative --ignore-submodules
1106 __git_fetch_options="
1107 --quiet --verbose --append --upload-pack --force --keep --depth=
1108 --tags --no-tags --all --prune --dry-run
1115 __gitcomp "$__git_fetch_options"
1119 __git_complete_remote_or_refspec
1122 _git_format_patch ()
1128 " "" "${cur##--thread=}"
1133 --stdout --attach --no-attach --thread --thread=
1135 --numbered --start-number
1138 --signoff --signature --no-signature
1139 --in-reply-to= --cc=
1140 --full-index --binary
1143 --no-prefix --src-prefix= --dst-prefix=
1144 --inline --suffix= --ignore-if-in-upstream
1150 __git_complete_revlist
1158 --tags --root --unreachable --cache --no-reflogs --full
1159 --strict --verbose --lost-found
1171 __gitcomp "--prune --aggressive"
1183 __git_match_ctag() {
1184 awk "/^${1////\\/}/ { print \$1 }" "$2"
1189 __git_has_doubledash && return
1195 --text --ignore-case --word-regexp --invert-match
1196 --full-name --line-number
1197 --extended-regexp --basic-regexp --fixed-strings
1199 --files-with-matches --name-only
1200 --files-without-match
1203 --and --or --not --all-match
1209 case "$cword,$prev" in
1211 if test -r tags; then
1212 __gitcomp_nl "$(__git_match_ctag "$cur" tags)"
1218 __gitcomp_nl "$(__git_refs)"
1225 __gitcomp "--all --info --man --web"
1229 __git_compute_all_commands
1230 __gitcomp "$__git_all_commands $(__git_aliases)
1231 attributes cli core-tutorial cvs-migration
1232 diffcore gitk glossary hooks ignore modules
1233 namespaces repository-layout tutorial tutorial-2
1243 false true umask group all world everybody
1244 " "" "${cur##--shared=}"
1248 __gitcomp "--quiet --bare --template= --shared --shared="
1257 __git_has_doubledash && return
1261 __gitcomp "--cached --deleted --modified --others --ignored
1262 --stage --directory --no-empty-directory --unmerged
1263 --killed --exclude= --exclude-from=
1264 --exclude-per-directory= --exclude-standard
1265 --error-unmatch --with-tree= --full-name
1266 --abbrev --ignored --exclude-per-directory
1276 __gitcomp_nl "$(__git_remotes)"
1284 # Options that go well for log, shortlog and gitk
1285 __git_log_common_options="
1287 --branches --tags --remotes
1288 --first-parent --merges --no-merges
1290 --max-age= --since= --after=
1291 --min-age= --until= --before=
1292 --min-parents= --max-parents=
1293 --no-min-parents --no-max-parents
1295 # Options that go well for log and gitk (not shortlog)
1296 __git_log_gitk_options="
1297 --dense --sparse --full-history
1298 --simplify-merges --simplify-by-decoration
1299 --left-right --notes --no-notes
1301 # Options that go well for log and shortlog (not gitk)
1302 __git_log_shortlog_options="
1303 --author= --committer= --grep=
1307 __git_log_pretty_formats="oneline short medium full fuller email raw format:"
1308 __git_log_date_formats="relative iso8601 rfc2822 short local default raw"
1312 __git_has_doubledash && return
1314 local g="$(git rev-parse --git-dir 2>/dev/null)"
1316 if [ -f "$g/MERGE_HEAD" ]; then
1320 --pretty=*|--format=*)
1321 __gitcomp "$__git_log_pretty_formats $(__git_pretty_aliases)
1326 __gitcomp "$__git_log_date_formats" "" "${cur##--date=}"
1330 __gitcomp "long short" "" "${cur##--decorate=}"
1335 $__git_log_common_options
1336 $__git_log_shortlog_options
1337 $__git_log_gitk_options
1338 --root --topo-order --date-order --reverse
1339 --follow --full-diff
1340 --abbrev-commit --abbrev=
1341 --relative-date --date=
1342 --pretty= --format= --oneline
1345 --decorate --decorate=
1347 --parents --children
1349 $__git_diff_common_options
1350 --pickaxe-all --pickaxe-regex
1355 __git_complete_revlist
1358 __git_merge_options="
1359 --no-commit --no-stat --log --no-log --squash --strategy
1360 --commit --stat --no-squash --ff --no-ff --ff-only --edit --no-edit
1365 __git_complete_strategy && return
1369 __gitcomp "$__git_merge_options"
1372 __gitcomp_nl "$(__git_refs)"
1379 __gitcomp "$__git_mergetools_common tortoisemerge" "" "${cur##--tool=}"
1392 __gitcomp_nl "$(__git_refs)"
1399 __gitcomp "--dry-run"
1408 __gitcomp "--tags --all --stdin"
1413 local subcommands='add append copy edit list prune remove show'
1414 local subcommand="$(__git_find_on_cmdline "$subcommands")"
1416 case "$subcommand,$cur" in
1423 __gitcomp_nl "$(__git_refs)"
1426 __gitcomp "$subcommands --ref"
1430 add,--reuse-message=*|append,--reuse-message=*|\
1431 add,--reedit-message=*|append,--reedit-message=*)
1432 __gitcomp_nl "$(__git_refs)" "" "${cur#*=}"
1435 __gitcomp '--file= --message= --reedit-message=
1442 __gitcomp '--dry-run --verbose'
1451 __gitcomp_nl "$(__git_refs)"
1460 __git_complete_strategy && return
1465 --rebase --no-rebase
1466 $__git_merge_options
1467 $__git_fetch_options
1472 __git_complete_remote_or_refspec
1479 __gitcomp_nl "$(__git_remotes)"
1484 __gitcomp_nl "$(__git_remotes)" "" "${cur##--repo=}"
1489 --all --mirror --tags --dry-run --force --verbose
1490 --receive-pack= --repo= --set-upstream
1495 __git_complete_remote_or_refspec
1500 local dir="$(__gitdir)"
1501 if [ -d "$dir"/rebase-apply ] || [ -d "$dir"/rebase-merge ]; then
1502 __gitcomp "--continue --skip --abort"
1505 __git_complete_strategy && return
1508 __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
1513 --onto --merge --strategy --interactive
1514 --preserve-merges --stat --no-stat
1515 --committer-date-is-author-date --ignore-date
1516 --ignore-whitespace --whitespace=
1522 __gitcomp_nl "$(__git_refs)"
1527 local subcommands="show delete expire"
1528 local subcommand="$(__git_find_on_cmdline "$subcommands")"
1530 if [ -z "$subcommand" ]; then
1531 __gitcomp "$subcommands"
1533 __gitcomp_nl "$(__git_refs)"
1537 __git_send_email_confirm_options="always never auto cc compose"
1538 __git_send_email_suppresscc_options="author self cc bodycc sob cccmd body all"
1545 $__git_send_email_confirm_options
1546 " "" "${cur##--confirm=}"
1551 $__git_send_email_suppresscc_options
1552 " "" "${cur##--suppress-cc=}"
1556 --smtp-encryption=*)
1557 __gitcomp "ssl tls" "" "${cur##--smtp-encryption=}"
1561 __gitcomp "--annotate --bcc --cc --cc-cmd --chain-reply-to
1562 --compose --confirm= --dry-run --envelope-sender
1564 --in-reply-to --no-chain-reply-to --no-signed-off-by-cc
1565 --no-suppress-from --no-thread --quiet
1566 --signed-off-by-cc --smtp-pass --smtp-server
1567 --smtp-server-port --smtp-encryption= --smtp-user
1568 --subject --suppress-cc= --suppress-from --thread --to
1569 --validate --no-validate"
1581 __git_config_get_set_variables ()
1583 local prevword word config_file= c=$cword
1584 while [ $c -gt 1 ]; do
1587 --global|--system|--file=*)
1592 config_file="$word $prevword"
1600 git --git-dir="$(__gitdir)" config $config_file --list 2>/dev/null |
1615 __gitcomp_nl "$(__git_remotes)"
1619 __gitcomp_nl "$(__git_refs)"
1623 local remote="${prev#remote.}"
1624 remote="${remote%.fetch}"
1625 if [ -z "$cur" ]; then
1626 COMPREPLY=("refs/heads/")
1629 __gitcomp_nl "$(__git_refs_remotes "$remote")"
1633 local remote="${prev#remote.}"
1634 remote="${remote%.push}"
1635 __gitcomp_nl "$(git --git-dir="$(__gitdir)" \
1636 for-each-ref --format='%(refname):%(refname)' \
1640 pull.twohead|pull.octopus)
1641 __git_compute_merge_strategies
1642 __gitcomp "$__git_merge_strategies"
1645 color.branch|color.diff|color.interactive|\
1646 color.showbranch|color.status|color.ui)
1647 __gitcomp "always never auto"
1651 __gitcomp "false true"
1656 normal black red green yellow blue magenta cyan white
1657 bold dim ul blink reverse
1662 __gitcomp "man info web html"
1666 __gitcomp "$__git_log_date_formats"
1669 sendemail.aliasesfiletype)
1670 __gitcomp "mutt mailrc pine elm gnus"
1674 __gitcomp "$__git_send_email_confirm_options"
1677 sendemail.suppresscc)
1678 __gitcomp "$__git_send_email_suppresscc_options"
1681 --get|--get-all|--unset|--unset-all)
1682 __gitcomp_nl "$(__git_config_get_set_variables)"
1693 --global --system --file=
1694 --list --replace-all
1695 --get --get-all --get-regexp
1696 --add --unset --unset-all
1697 --remove-section --rename-section
1702 local pfx="${cur%.*}." cur_="${cur##*.}"
1703 __gitcomp "remote merge mergeoptions rebase" "$pfx" "$cur_"
1707 local pfx="${cur%.*}." cur_="${cur#*.}"
1708 __gitcomp_nl "$(__git_heads)" "$pfx" "$cur_" "."
1712 local pfx="${cur%.*}." cur_="${cur##*.}"
1714 argprompt cmd confirm needsfile noconsole norescan
1715 prompt revprompt revunmerged title
1720 local pfx="${cur%.*}." cur_="${cur##*.}"
1721 __gitcomp "cmd path" "$pfx" "$cur_"
1725 local pfx="${cur%.*}." cur_="${cur##*.}"
1726 __gitcomp "cmd path" "$pfx" "$cur_"
1730 local pfx="${cur%.*}." cur_="${cur##*.}"
1731 __gitcomp "cmd path trustExitCode" "$pfx" "$cur_"
1735 local pfx="${cur%.*}." cur_="${cur#*.}"
1736 __git_compute_all_commands
1737 __gitcomp_nl "$__git_all_commands" "$pfx" "$cur_"
1741 local pfx="${cur%.*}." cur_="${cur##*.}"
1743 url proxy fetch push mirror skipDefaultUpdate
1744 receivepack uploadpack tagopt pushurl
1749 local pfx="${cur%.*}." cur_="${cur#*.}"
1750 __gitcomp_nl "$(__git_remotes)" "$pfx" "$cur_" "."
1754 local pfx="${cur%.*}." cur_="${cur##*.}"
1755 __gitcomp "insteadOf pushInsteadOf" "$pfx" "$cur_"
1761 advice.commitBeforeMerge
1763 advice.implicitIdentity
1764 advice.pushNonFastForward
1765 advice.resolveConflict
1769 apply.ignorewhitespace
1771 branch.autosetupmerge
1772 branch.autosetuprebase
1776 color.branch.current
1781 color.decorate.branch
1782 color.decorate.remoteBranch
1783 color.decorate.stash
1793 color.diff.whitespace
1798 color.grep.linenumber
1801 color.grep.separator
1803 color.interactive.error
1804 color.interactive.header
1805 color.interactive.help
1806 color.interactive.prompt
1811 color.status.changed
1813 color.status.nobranch
1814 color.status.untracked
1815 color.status.updated
1824 core.bigFileThreshold
1827 core.deltaBaseCacheLimit
1832 core.fsyncobjectfiles
1834 core.ignoreCygwinFSTricks
1837 core.logAllRefUpdates
1838 core.loosecompression
1841 core.packedGitWindowSize
1843 core.preferSymlinkRefs
1846 core.repositoryFormatVersion
1848 core.sharedRepository
1852 core.warnAmbiguousRefs
1855 diff.autorefreshindex
1858 diff.ignoreSubmodules
1863 diff.suppressBlankEmpty
1868 fetch.recurseSubmodules
1877 format.subjectprefix
1888 gc.reflogexpireunreachable
1892 gitcvs.commitmsgannotation
1893 gitcvs.dbTableNamePrefix
1904 gui.copyblamethreshold
1908 gui.matchtrackingbranch
1909 gui.newbranchtemplate
1910 gui.pruneduringfetch
1911 gui.spellingdictionary
1926 http.sslCertPasswordProtected
1931 i18n.logOutputEncoding
1937 imap.preformattedHTML
1947 interactive.singlekey
1963 mergetool.keepBackup
1964 mergetool.keepTemporaries
1969 notes.rewrite.rebase
1973 pack.deltaCacheLimit
1989 receive.denyCurrentBranch
1990 receive.denyDeleteCurrent
1992 receive.denyNonFastForwards
1995 receive.updateserverinfo
1997 repack.usedeltabaseoffset
2001 sendemail.aliasesfile
2002 sendemail.aliasfiletype
2006 sendemail.chainreplyto
2008 sendemail.envelopesender
2012 sendemail.signedoffbycc
2013 sendemail.smtpdomain
2014 sendemail.smtpencryption
2016 sendemail.smtpserver
2017 sendemail.smtpserveroption
2018 sendemail.smtpserverport
2020 sendemail.suppresscc
2021 sendemail.suppressfrom
2026 status.relativePaths
2027 status.showUntrackedFiles
2028 status.submodulesummary
2031 transfer.unpackLimit
2043 local subcommands="add rename remove set-head set-branches set-url show prune update"
2044 local subcommand="$(__git_find_on_cmdline "$subcommands")"
2045 if [ -z "$subcommand" ]; then
2046 __gitcomp "$subcommands"
2050 case "$subcommand" in
2051 rename|remove|set-url|show|prune)
2052 __gitcomp_nl "$(__git_remotes)"
2054 set-head|set-branches)
2055 __git_complete_remote_or_refspec
2058 local i c='' IFS=$'\n'
2059 for i in $(git --git-dir="$(__gitdir)" config --get-regexp "remotes\..*" 2>/dev/null); do
2073 __gitcomp_nl "$(__git_refs)"
2078 __git_has_doubledash && return
2082 __gitcomp "--merge --mixed --hard --soft --patch"
2086 __gitcomp_nl "$(__git_refs)"
2093 __gitcomp "--edit --mainline --no-edit --no-commit --signoff"
2097 __gitcomp_nl "$(__git_refs)"
2102 __git_has_doubledash && return
2106 __gitcomp "--cached --dry-run --ignore-unmatch --quiet"
2115 __git_has_doubledash && return
2120 $__git_log_common_options
2121 $__git_log_shortlog_options
2122 --numbered --summary
2127 __git_complete_revlist
2132 __git_has_doubledash && return
2135 --pretty=*|--format=*)
2136 __gitcomp "$__git_log_pretty_formats $(__git_pretty_aliases)
2141 __gitcomp "--pretty= --format= --abbrev-commit --oneline
2142 $__git_diff_common_options
2155 --all --remotes --topo-order --current --more=
2156 --list --independent --merge-base --no-name
2158 --sha1-name --sparse --topics --reflog
2163 __git_complete_revlist
2168 local save_opts='--keep-index --no-keep-index --quiet --patch'
2169 local subcommands='save list show apply clear drop pop create branch'
2170 local subcommand="$(__git_find_on_cmdline "$subcommands")"
2171 if [ -z "$subcommand" ]; then
2174 __gitcomp "$save_opts"
2177 if [ -z "$(__git_find_on_cmdline "$save_opts")" ]; then
2178 __gitcomp "$subcommands"
2185 case "$subcommand,$cur" in
2187 __gitcomp "$save_opts"
2190 __gitcomp "--index --quiet"
2192 show,--*|drop,--*|branch,--*)
2195 show,*|apply,*|drop,*|pop,*|branch,*)
2196 __gitcomp_nl "$(git --git-dir="$(__gitdir)" stash list \
2197 | sed -n -e 's/:.*//p')"
2208 __git_has_doubledash && return
2210 local subcommands="add status init update summary foreach sync"
2211 if [ -z "$(__git_find_on_cmdline "$subcommands")" ]; then
2214 __gitcomp "--quiet --cached"
2217 __gitcomp "$subcommands"
2227 init fetch clone rebase dcommit log find-rev
2228 set-tree commit-diff info create-ignore propget
2229 proplist show-ignore show-externals branch tag blame
2230 migrate mkdirs reset gc
2232 local subcommand="$(__git_find_on_cmdline "$subcommands")"
2233 if [ -z "$subcommand" ]; then
2234 __gitcomp "$subcommands"
2236 local remote_opts="--username= --config-dir= --no-auth-cache"
2238 --follow-parent --authors-file= --repack=
2239 --no-metadata --use-svm-props --use-svnsync-props
2240 --log-window-size= --no-checkout --quiet
2241 --repack-flags --use-log-author --localtime
2242 --ignore-paths= $remote_opts
2245 --template= --shared= --trunk= --tags=
2246 --branches= --stdlayout --minimize-url
2247 --no-metadata --use-svm-props --use-svnsync-props
2248 --rewrite-root= --prefix= --use-log-author
2249 --add-author-from $remote_opts
2252 --edit --rmdir --find-copies-harder --copy-similarity=
2255 case "$subcommand,$cur" in
2257 __gitcomp "--revision= --fetch-all $fc_opts"
2260 __gitcomp "--revision= $fc_opts $init_opts"
2263 __gitcomp "$init_opts"
2267 --merge --strategy= --verbose --dry-run
2268 --fetch-all --no-rebase --commit-url
2269 --revision --interactive $cmt_opts $fc_opts
2273 __gitcomp "--stdin $cmt_opts $fc_opts"
2275 create-ignore,--*|propget,--*|proplist,--*|show-ignore,--*|\
2276 show-externals,--*|mkdirs,--*)
2277 __gitcomp "--revision="
2281 --limit= --revision= --verbose --incremental
2282 --oneline --show-commit --non-recursive
2283 --authors-file= --color
2288 --merge --verbose --strategy= --local
2289 --fetch-all --dry-run $fc_opts
2293 __gitcomp "--message= --file= --revision= $cmt_opts"
2299 __gitcomp "--dry-run --message --tag"
2302 __gitcomp "--dry-run --message"
2305 __gitcomp "--git-format"
2309 --config-dir= --ignore-paths= --minimize
2310 --no-auth-cache --username=
2314 __gitcomp "--revision= --parent"
2326 while [ $c -lt $cword ]; do
2330 __gitcomp_nl "$(__git_tags)"
2346 __gitcomp_nl "$(__git_tags)"
2352 __gitcomp_nl "$(__git_refs)"
2364 local i c=1 command __git_dir
2366 while [ $c -lt $cword ]; do
2369 --git-dir=*) __git_dir="${i#--git-dir=}" ;;
2370 --bare) __git_dir="." ;;
2371 --help) command="help"; break ;;
2374 *) command="$i"; break ;;
2379 if [ -z "$command" ]; then
2393 --no-replace-objects
2397 *) __git_compute_porcelain_commands
2398 __gitcomp "$__git_porcelain_commands $(__git_aliases)" ;;
2403 local completion_func="_git_${command//-/_}"
2404 declare -f $completion_func >/dev/null && $completion_func && return
2406 local expansion=$(__git_aliased_command "$command")
2407 if [ -n "$expansion" ]; then
2408 completion_func="_git_${expansion//-/_}"
2409 declare -f $completion_func >/dev/null && $completion_func
2415 __git_has_doubledash && return
2417 local g="$(__gitdir)"
2419 if [ -f "$g/MERGE_HEAD" ]; then
2425 $__git_log_common_options
2426 $__git_log_gitk_options
2432 __git_complete_revlist
2437 if [[ -n ${ZSH_VERSION-} ]]; then
2441 # workaround zsh's bug that leaves 'words' as a special
2442 # variable in versions < 4.3.12
2445 # workaround zsh's bug that quotes spaces in the COMPREPLY
2446 # array if IFS doesn't contain spaces.
2449 local cur words cword prev
2450 _get_comp_words_by_ref -n =: cur words cword prev
2454 # Setup completion for certain functions defined above by setting common
2455 # variables and workarounds.
2456 # This is NOT a public function; use at your own risk.
2459 local wrapper="__git_wrap${2}"
2460 eval "$wrapper () { __git_func_wrap $2 ; }"
2461 complete -o bashdefault -o default -o nospace -F $wrapper $1 2>/dev/null \
2462 || complete -o default -o nospace -F $wrapper $1
2465 # wrapper for backwards compatibility
2468 __git_wrap__git_main
2471 # wrapper for backwards compatibility
2474 __git_wrap__gitk_main
2477 __git_complete git __git_main
2478 __git_complete gitk __gitk_main
2480 # The following are necessary only for Cygwin, and only are needed
2481 # when the user has tab-completed the executable name and consequently
2482 # included the '.exe' suffix.
2484 if [ Cygwin = "$(uname -o 2>/dev/null)" ]; then
2485 __git_complete git.exe __git_main