1 # bash completion support for core Git.
3 # Copyright (C) 2006,2007 Shawn O. Pearce <spearce@spearce.org>
4 # Conceptually based on gitcompletion (http://gitweb.hawaga.org.uk/).
5 # Distributed under the GNU General Public License, version 2.0.
7 # The contained completion routines provide support for completing:
9 # *) local and remote branch names
10 # *) local and remote tag names
11 # *) .git/remotes file names
12 # *) git 'subcommands'
13 # *) tree paths within 'ref:path/to/file' expressions
14 # *) common --long-options
16 # To use these routines:
18 # 1) Copy this file to somewhere (e.g. ~/.git-completion.sh).
19 # 2) Added the following line to your .bashrc:
20 # source ~/.git-completion.sh
22 # 3) Consider changing your PS1 to also show the current branch:
23 # PS1='[\u@\h \W$(__git_ps1 " (%s)")]\$ '
25 # The argument to __git_ps1 will be displayed only if you
26 # are currently in a git repository. The %s token will be
27 # the name of the current branch.
29 # In addition, if you set GIT_PS1_SHOWDIRTYSTATE to a nonempty
30 # value, unstaged (*) and staged (+) changes will be shown next
31 # to the branch name. You can configure this per-repository
32 # with the bash.showDirtyState variable, which defaults to true
33 # once GIT_PS1_SHOWDIRTYSTATE is enabled.
35 # You can also see if currently something is stashed, by setting
36 # GIT_PS1_SHOWSTASHSTATE to a nonempty value. If something is stashed,
37 # then a '$' will be shown next to the branch name.
39 # If you would like to see if there're untracked files, then you can
40 # set GIT_PS1_SHOWUNTRACKEDFILES to a nonempty value. If there're
41 # untracked files, then a '%' will be shown next to the branch name.
45 # *) Read Documentation/SubmittingPatches
46 # *) Send all patches to the current maintainer:
48 # "Shawn O. Pearce" <spearce@spearce.org>
50 # *) Always CC the Git mailing list:
55 case "$COMP_WORDBREAKS" in
57 *) COMP_WORDBREAKS="$COMP_WORDBREAKS:"
60 # __gitdir accepts 0 or 1 arguments (i.e., location)
61 # returns location of .git repo
64 if [ -z "${1-}" ]; then
65 if [ -n "${__git_dir-}" ]; then
67 elif [ -d .git ]; then
70 git rev-parse --git-dir 2>/dev/null
72 elif [ -d "$1/.git" ]; then
79 # __git_ps1 accepts 0 or 1 arguments (i.e., format string)
80 # returns text to add to bash PS1 prompt (includes branch name)
87 if [ -f "$g/rebase-merge/interactive" ]; then
89 b="$(cat "$g/rebase-merge/head-name")"
90 elif [ -d "$g/rebase-merge" ]; then
92 b="$(cat "$g/rebase-merge/head-name")"
94 if [ -d "$g/rebase-apply" ]; then
95 if [ -f "$g/rebase-apply/rebasing" ]; then
97 elif [ -f "$g/rebase-apply/applying" ]; then
102 elif [ -f "$g/MERGE_HEAD" ]; then
104 elif [ -f "$g/BISECT_LOG" ]; then
108 b="$(git symbolic-ref HEAD 2>/dev/null)" || {
111 case "${GIT_PS1_DESCRIBE_STYLE-}" in
113 git describe --contains HEAD ;;
115 git describe --contains --all HEAD ;;
119 git describe --exact-match HEAD ;;
120 esac 2>/dev/null)" ||
122 b="$(cut -c1-7 "$g/HEAD" 2>/dev/null)..." || return
132 if [ "true" = "$(git rev-parse --is-inside-git-dir 2>/dev/null)" ]; then
133 if [ "true" = "$(git rev-parse --is-bare-repository 2>/dev/null)" ]; then
138 elif [ "true" = "$(git rev-parse --is-inside-work-tree 2>/dev/null)" ]; then
139 if [ -n "${GIT_PS1_SHOWDIRTYSTATE-}" ]; then
140 if [ "$(git config --bool bash.showDirtyState)" != "false" ]; then
141 git diff --no-ext-diff --quiet --exit-code || w="*"
142 if git rev-parse --quiet --verify HEAD >/dev/null; then
143 git diff-index --cached --quiet HEAD -- || i="+"
149 if [ -n "${GIT_PS1_SHOWSTASHSTATE-}" ]; then
150 git rev-parse --verify refs/stash >/dev/null 2>&1 && s="$"
153 if [ -n "${GIT_PS1_SHOWUNTRACKEDFILES-}" ]; then
154 if [ -n "$(git ls-files --others --exclude-standard)" ]; then
161 printf "${1:- (%s)}" "$c${b##refs/heads/}${f:+$f}$r"
165 # __gitcomp_1 requires 2 arguments
168 local c IFS=' '$'\t'$'\n'
171 --*=*) printf %s$'\n' "$c$2" ;;
172 *.) printf %s$'\n' "$c$2" ;;
173 *) printf %s$'\n' "$c$2 " ;;
178 # __gitcomp accepts 1, 2, 3, or 4 arguments
179 # generates completion reply with compgen
182 local cur="${COMP_WORDS[COMP_CWORD]}"
183 if [ $# -gt 2 ]; then
192 COMPREPLY=($(compgen -P "${2-}" \
193 -W "$(__gitcomp_1 "${1-}" "${4-}")" \
199 # __git_heads accepts 0 or 1 arguments (to pass to __gitdir)
202 local cmd i is_hash=y dir="$(__gitdir "${1-}")"
203 if [ -d "$dir" ]; then
204 git --git-dir="$dir" for-each-ref --format='%(refname:short)' \
208 for i in $(git ls-remote "${1-}" 2>/dev/null); do
209 case "$is_hash,$i" in
212 n,refs/heads/*) is_hash=y; echo "${i#refs/heads/}" ;;
213 n,*) is_hash=y; echo "$i" ;;
218 # __git_tags accepts 0 or 1 arguments (to pass to __gitdir)
221 local cmd i is_hash=y dir="$(__gitdir "${1-}")"
222 if [ -d "$dir" ]; then
223 git --git-dir="$dir" for-each-ref --format='%(refname:short)' \
227 for i in $(git ls-remote "${1-}" 2>/dev/null); do
228 case "$is_hash,$i" in
231 n,refs/tags/*) is_hash=y; echo "${i#refs/tags/}" ;;
232 n,*) is_hash=y; echo "$i" ;;
237 # __git_refs accepts 0 or 1 arguments (to pass to __gitdir)
240 local i is_hash=y dir="$(__gitdir "${1-}")"
241 local cur="${COMP_WORDS[COMP_CWORD]}" format refs
242 if [ -d "$dir" ]; then
249 if [ -e "$dir/HEAD" ]; then echo HEAD; fi
250 format="refname:short"
251 refs="refs/tags refs/heads refs/remotes"
254 git --git-dir="$dir" for-each-ref --format="%($format)" \
258 for i in $(git ls-remote "$dir" 2>/dev/null); do
259 case "$is_hash,$i" in
262 n,refs/tags/*) is_hash=y; echo "${i#refs/tags/}" ;;
263 n,refs/heads/*) is_hash=y; echo "${i#refs/heads/}" ;;
264 n,refs/remotes/*) is_hash=y; echo "${i#refs/remotes/}" ;;
265 n,*) is_hash=y; echo "$i" ;;
270 # __git_refs2 requires 1 argument (to pass to __git_refs)
274 for i in $(__git_refs "$1"); do
279 # __git_refs_remotes requires 1 argument (to pass to ls-remote)
280 __git_refs_remotes ()
282 local cmd i is_hash=y
283 for i in $(git ls-remote "$1" 2>/dev/null); do
284 case "$is_hash,$i" in
287 echo "$i:refs/remotes/$1/${i#refs/heads/}"
291 n,refs/tags/*) is_hash=y;;
299 local i ngoff IFS=$'\n' d="$(__gitdir)"
300 shopt -q nullglob || ngoff=1
302 for i in "$d/remotes"/*; do
303 echo ${i#$d/remotes/}
305 [ "$ngoff" ] && shopt -u nullglob
306 for i in $(git --git-dir="$d" config --get-regexp 'remote\..*\.url' 2>/dev/null); do
312 __git_list_merge_strategies ()
314 git merge -s help 2>&1 |
315 sed -n -e '/[Aa]vailable strategies are: /,/^$/{
324 __git_merge_strategies=
325 # 'git merge -s help' (and thus detection of the merge strategy
326 # list) fails, unfortunately, if run outside of any git working
327 # tree. __git_merge_strategies is set to the empty string in
328 # that case, and the detection will be repeated the next time it
330 __git_compute_merge_strategies ()
332 : ${__git_merge_strategies:=$(__git_list_merge_strategies)}
335 __git_complete_file ()
337 local pfx ls ref cur="${COMP_WORDS[COMP_CWORD]}"
354 case "$COMP_WORDBREAKS" in
356 *) pfx="$ref:$pfx" ;;
360 COMPREPLY=($(compgen -P "$pfx" \
361 -W "$(git --git-dir="$(__gitdir)" ls-tree "$ls" \
362 | sed '/^100... blob /{
378 __gitcomp "$(__git_refs)"
383 __git_complete_revlist ()
385 local pfx cur="${COMP_WORDS[COMP_CWORD]}"
390 __gitcomp "$(__git_refs)" "$pfx" "$cur"
395 __gitcomp "$(__git_refs)" "$pfx" "$cur"
398 __gitcomp "$(__git_refs)"
403 __git_complete_remote_or_refspec ()
405 local cmd="${COMP_WORDS[1]}"
406 local cur="${COMP_WORDS[COMP_CWORD]}"
407 local i c=2 remote="" pfx="" lhs=1 no_complete_refspec=0
408 while [ $c -lt $COMP_CWORD ]; do
411 --mirror) [ "$cmd" = "push" ] && no_complete_refspec=1 ;;
414 push) no_complete_refspec=1 ;;
423 *) remote="$i"; break ;;
427 if [ -z "$remote" ]; then
428 __gitcomp "$(__git_remotes)"
431 if [ $no_complete_refspec = 1 ]; then
435 [ "$remote" = "." ] && remote=
438 case "$COMP_WORDBREAKS" in
440 *) pfx="${cur%%:*}:" ;;
452 if [ $lhs = 1 ]; then
453 __gitcomp "$(__git_refs2 "$remote")" "$pfx" "$cur"
455 __gitcomp "$(__git_refs)" "$pfx" "$cur"
459 if [ $lhs = 1 ]; then
460 __gitcomp "$(__git_refs "$remote")" "$pfx" "$cur"
462 __gitcomp "$(__git_refs)" "$pfx" "$cur"
466 if [ $lhs = 1 ]; then
467 __gitcomp "$(__git_refs)" "$pfx" "$cur"
469 __gitcomp "$(__git_refs "$remote")" "$pfx" "$cur"
475 __git_complete_strategy ()
477 __git_compute_merge_strategies
478 case "${COMP_WORDS[COMP_CWORD-1]}" in
480 __gitcomp "$__git_merge_strategies"
483 local cur="${COMP_WORDS[COMP_CWORD]}"
486 __gitcomp "$__git_merge_strategies" "" "${cur##--strategy=}"
493 __git_list_all_commands ()
496 for i in $(git help -a|egrep '^ [a-zA-Z0-9]')
499 *--*) : helper pattern;;
506 __git_compute_all_commands ()
508 : ${__git_all_commands:=$(__git_list_all_commands)}
511 __git_list_porcelain_commands ()
514 __git_compute_all_commands
515 for i in "help" $__git_all_commands
518 *--*) : helper pattern;;
519 applymbox) : ask gittus;;
520 applypatch) : ask gittus;;
521 archimport) : import;;
522 cat-file) : plumbing;;
523 check-attr) : plumbing;;
524 check-ref-format) : plumbing;;
525 checkout-index) : plumbing;;
526 commit-tree) : plumbing;;
527 count-objects) : infrequent;;
528 cvsexportcommit) : export;;
529 cvsimport) : import;;
530 cvsserver) : daemon;;
532 diff-files) : plumbing;;
533 diff-index) : plumbing;;
534 diff-tree) : plumbing;;
535 fast-import) : import;;
536 fast-export) : export;;
537 fsck-objects) : plumbing;;
538 fetch-pack) : plumbing;;
539 fmt-merge-msg) : plumbing;;
540 for-each-ref) : plumbing;;
541 hash-object) : plumbing;;
542 http-*) : transport;;
543 index-pack) : plumbing;;
544 init-db) : deprecated;;
545 local-fetch) : plumbing;;
546 lost-found) : infrequent;;
547 ls-files) : plumbing;;
548 ls-remote) : plumbing;;
549 ls-tree) : plumbing;;
550 mailinfo) : plumbing;;
551 mailsplit) : plumbing;;
552 merge-*) : plumbing;;
555 pack-objects) : plumbing;;
556 pack-redundant) : plumbing;;
557 pack-refs) : plumbing;;
558 parse-remote) : plumbing;;
559 patch-id) : plumbing;;
560 peek-remote) : plumbing;;
562 prune-packed) : plumbing;;
563 quiltimport) : import;;
564 read-tree) : plumbing;;
565 receive-pack) : plumbing;;
567 remote-*) : transport;;
568 repo-config) : deprecated;;
570 rev-list) : plumbing;;
571 rev-parse) : plumbing;;
572 runstatus) : plumbing;;
573 sh-setup) : internal;;
575 show-ref) : plumbing;;
576 send-pack) : plumbing;;
577 show-index) : plumbing;;
579 stripspace) : plumbing;;
580 symbolic-ref) : plumbing;;
581 tar-tree) : deprecated;;
582 unpack-file) : plumbing;;
583 unpack-objects) : plumbing;;
584 update-index) : plumbing;;
585 update-ref) : plumbing;;
586 update-server-info) : daemon;;
587 upload-archive) : plumbing;;
588 upload-pack) : plumbing;;
589 write-tree) : plumbing;;
591 verify-pack) : infrequent;;
592 verify-tag) : plumbing;;
598 __git_porcelain_commands=
599 __git_compute_porcelain_commands ()
601 __git_compute_all_commands
602 : ${__git_porcelain_commands:=$(__git_list_porcelain_commands)}
608 for i in $(git --git-dir="$(__gitdir)" config --get-regexp "alias\..*" 2>/dev/null); do
618 # __git_aliased_command requires 1 argument
619 __git_aliased_command ()
621 local word cmdline=$(git --git-dir="$(__gitdir)" \
622 config --get "alias.$1")
623 for word in $cmdline; do
624 if [ "${word##-*}" ]; then
631 # __git_find_on_cmdline requires 1 argument
632 __git_find_on_cmdline ()
634 local word subcommand c=1
636 while [ $c -lt $COMP_CWORD ]; do
637 word="${COMP_WORDS[c]}"
638 for subcommand in $1; do
639 if [ "$subcommand" = "$word" ]; then
648 __git_has_doubledash ()
651 while [ $c -lt $COMP_CWORD ]; do
652 if [ "--" = "${COMP_WORDS[c]}" ]; then
660 __git_whitespacelist="nowarn warn error error-all fix"
664 local cur="${COMP_WORDS[COMP_CWORD]}" dir="$(__gitdir)"
665 if [ -d "$dir"/rebase-apply ]; then
666 __gitcomp "--skip --continue --resolved --abort"
671 __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
676 --3way --committer-date-is-author-date --ignore-date
677 --ignore-whitespace --ignore-space-change
678 --interactive --keep --no-utf8 --signoff --utf8
679 --whitespace= --scissors
688 local cur="${COMP_WORDS[COMP_CWORD]}"
691 __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
696 --stat --numstat --summary --check --index
697 --cached --index-info --reverse --reject --unidiff-zero
698 --apply --no-add --exclude=
699 --ignore-whitespace --ignore-space-change
700 --whitespace= --inaccurate-eof --verbose
709 __git_has_doubledash && return
711 local cur="${COMP_WORDS[COMP_CWORD]}"
715 --interactive --refresh --patch --update --dry-run
716 --ignore-errors --intent-to-add
725 local cur="${COMP_WORDS[COMP_CWORD]}"
728 __gitcomp "$(git archive --list)" "" "${cur##--format=}"
732 __gitcomp "$(__git_remotes)" "" "${cur##--remote=}"
737 --format= --list --verbose
738 --prefix= --remote= --exec=
748 __git_has_doubledash && return
750 local subcommands="start bad good skip reset visualize replay log run"
751 local subcommand="$(__git_find_on_cmdline "$subcommands")"
752 if [ -z "$subcommand" ]; then
753 __gitcomp "$subcommands"
757 case "$subcommand" in
759 __gitcomp "$(__git_refs)"
769 local i c=1 only_local_ref="n" has_r="n"
771 while [ $c -lt $COMP_CWORD ]; do
774 -d|-m) only_local_ref="y" ;;
780 case "${COMP_WORDS[COMP_CWORD]}" in
783 --color --no-color --verbose --abbrev= --no-abbrev
784 --track --no-track --contains --merged --no-merged
788 if [ $only_local_ref = "y" -a $has_r = "n" ]; then
789 __gitcomp "$(__git_heads)"
791 __gitcomp "$(__git_refs)"
799 local cmd="${COMP_WORDS[2]}"
800 case "$COMP_CWORD" in
802 __gitcomp "create list-heads verify unbundle"
810 __git_complete_revlist
819 __git_has_doubledash && return
821 local cur="${COMP_WORDS[COMP_CWORD]}"
824 __gitcomp "diff3 merge" "" "${cur##--conflict=}"
828 --quiet --ours --theirs --track --no-track --merge
833 __gitcomp "$(__git_refs)"
840 __gitcomp "$(__git_refs)"
845 local cur="${COMP_WORDS[COMP_CWORD]}"
848 __gitcomp "--edit --no-commit"
851 __gitcomp "$(__git_refs)"
858 __git_has_doubledash && return
860 local cur="${COMP_WORDS[COMP_CWORD]}"
863 __gitcomp "--dry-run --quiet"
872 local cur="${COMP_WORDS[COMP_CWORD]}"
897 __git_has_doubledash && return
899 local cur="${COMP_WORDS[COMP_CWORD]}"
902 __gitcomp "default strip verbatim whitespace
903 " "" "${cur##--cleanup=}"
907 __gitcomp "$(__git_refs)" "" "${cur##--reuse-message=}"
911 __gitcomp "$(__git_refs)" "" "${cur##--reedit-message=}"
915 __gitcomp "all no normal" "" "${cur##--untracked-files=}"
920 --all --author= --signoff --verify --no-verify
921 --edit --amend --include --only --interactive
922 --dry-run --reuse-message= --reedit-message=
923 --reset-author --file= --message= --template=
924 --cleanup= --untracked-files --untracked-files=
934 local cur="${COMP_WORDS[COMP_CWORD]}"
938 --all --tags --contains --abbrev= --candidates=
939 --exact-match --debug --long --match --always
943 __gitcomp "$(__git_refs)"
946 __git_diff_common_options="--stat --numstat --shortstat --summary
947 --patch-with-stat --name-only --name-status --color
948 --no-color --color-words --no-renames --check
949 --full-index --binary --abbrev --diff-filter=
951 --text --ignore-space-at-eol --ignore-space-change
952 --ignore-all-space --exit-code --quiet --ext-diff
954 --no-prefix --src-prefix= --dst-prefix=
955 --inter-hunk-context=
958 --dirstat --dirstat= --dirstat-by-file
959 --dirstat-by-file= --cumulative
964 __git_has_doubledash && return
966 local cur="${COMP_WORDS[COMP_CWORD]}"
969 __gitcomp "--cached --staged --pickaxe-all --pickaxe-regex
970 --base --ours --theirs
971 $__git_diff_common_options
979 __git_mergetools_common="diffuse ecmerge emerge kdiff3 meld opendiff
980 tkdiff vimdiff gvimdiff xxdiff araxis p4merge
985 __git_has_doubledash && return
987 local cur="${COMP_WORDS[COMP_CWORD]}"
990 __gitcomp "$__git_mergetools_common kompare" "" "${cur##--tool=}"
994 __gitcomp "--cached --staged --pickaxe-all --pickaxe-regex
995 --base --ours --theirs
996 --no-renames --diff-filter= --find-copies-harder
997 --relative --ignore-submodules
1005 __git_fetch_options="
1006 --quiet --verbose --append --upload-pack --force --keep --depth=
1007 --tags --no-tags --all --prune --dry-run
1012 local cur="${COMP_WORDS[COMP_CWORD]}"
1015 __gitcomp "$__git_fetch_options"
1019 __git_complete_remote_or_refspec
1022 _git_format_patch ()
1024 local cur="${COMP_WORDS[COMP_CWORD]}"
1029 " "" "${cur##--thread=}"
1034 --stdout --attach --no-attach --thread --thread=
1036 --numbered --start-number
1040 --in-reply-to= --cc=
1041 --full-index --binary
1044 --no-prefix --src-prefix= --dst-prefix=
1045 --inline --suffix= --ignore-if-in-upstream
1051 __git_complete_revlist
1056 local cur="${COMP_WORDS[COMP_CWORD]}"
1060 --tags --root --unreachable --cache --no-reflogs --full
1061 --strict --verbose --lost-found
1071 local cur="${COMP_WORDS[COMP_CWORD]}"
1074 __gitcomp "--prune --aggressive"
1083 __git_has_doubledash && return
1085 local cur="${COMP_WORDS[COMP_CWORD]}"
1090 --text --ignore-case --word-regexp --invert-match
1092 --extended-regexp --basic-regexp --fixed-strings
1093 --files-with-matches --name-only
1094 --files-without-match
1097 --and --or --not --all-match
1103 __gitcomp "$(__git_refs)"
1108 local cur="${COMP_WORDS[COMP_CWORD]}"
1111 __gitcomp "--all --info --man --web"
1115 __git_compute_all_commands
1116 __gitcomp "$__git_all_commands
1117 attributes cli core-tutorial cvs-migration
1118 diffcore gitk glossary hooks ignore modules
1119 repository-layout tutorial tutorial-2
1126 local cur="${COMP_WORDS[COMP_CWORD]}"
1130 false true umask group all world everybody
1131 " "" "${cur##--shared=}"
1135 __gitcomp "--quiet --bare --template= --shared --shared="
1144 __git_has_doubledash && return
1146 local cur="${COMP_WORDS[COMP_CWORD]}"
1149 __gitcomp "--cached --deleted --modified --others --ignored
1150 --stage --directory --no-empty-directory --unmerged
1151 --killed --exclude= --exclude-from=
1152 --exclude-per-directory= --exclude-standard
1153 --error-unmatch --with-tree= --full-name
1154 --abbrev --ignored --exclude-per-directory
1164 __gitcomp "$(__git_remotes)"
1172 # Options that go well for log, shortlog and gitk
1173 __git_log_common_options="
1175 --branches --tags --remotes
1176 --first-parent --merges --no-merges
1178 --max-age= --since= --after=
1179 --min-age= --until= --before=
1181 # Options that go well for log and gitk (not shortlog)
1182 __git_log_gitk_options="
1183 --dense --sparse --full-history
1184 --simplify-merges --simplify-by-decoration
1187 # Options that go well for log and shortlog (not gitk)
1188 __git_log_shortlog_options="
1189 --author= --committer= --grep=
1193 __git_log_pretty_formats="oneline short medium full fuller email raw format:"
1194 __git_log_date_formats="relative iso8601 rfc2822 short local default raw"
1198 __git_has_doubledash && return
1200 local cur="${COMP_WORDS[COMP_CWORD]}"
1201 local g="$(git rev-parse --git-dir 2>/dev/null)"
1203 if [ -f "$g/MERGE_HEAD" ]; then
1208 __gitcomp "$__git_log_pretty_formats
1209 " "" "${cur##--pretty=}"
1213 __gitcomp "$__git_log_pretty_formats
1214 " "" "${cur##--format=}"
1218 __gitcomp "$__git_log_date_formats" "" "${cur##--date=}"
1222 __gitcomp "long short" "" "${cur##--decorate=}"
1227 $__git_log_common_options
1228 $__git_log_shortlog_options
1229 $__git_log_gitk_options
1230 --root --topo-order --date-order --reverse
1231 --follow --full-diff
1232 --abbrev-commit --abbrev=
1233 --relative-date --date=
1234 --pretty= --format= --oneline
1237 --decorate --decorate=
1239 --parents --children
1241 $__git_diff_common_options
1242 --pickaxe-all --pickaxe-regex
1247 __git_complete_revlist
1250 __git_merge_options="
1251 --no-commit --no-stat --log --no-log --squash --strategy
1252 --commit --stat --no-squash --ff --no-ff --ff-only
1257 __git_complete_strategy && return
1259 local cur="${COMP_WORDS[COMP_CWORD]}"
1262 __gitcomp "$__git_merge_options"
1265 __gitcomp "$(__git_refs)"
1270 local cur="${COMP_WORDS[COMP_CWORD]}"
1273 __gitcomp "$__git_mergetools_common tortoisemerge" "" "${cur##--tool=}"
1286 __gitcomp "$(__git_refs)"
1291 local cur="${COMP_WORDS[COMP_CWORD]}"
1294 __gitcomp "--dry-run"
1303 __gitcomp "--tags --all --stdin"
1308 local subcommands="edit show"
1309 if [ -z "$(__git_find_on_cmdline "$subcommands")" ]; then
1310 __gitcomp "$subcommands"
1314 case "${COMP_WORDS[COMP_CWORD-1]}" in
1319 __gitcomp "$(__git_refs)"
1326 __git_complete_strategy && return
1328 local cur="${COMP_WORDS[COMP_CWORD]}"
1332 --rebase --no-rebase
1333 $__git_merge_options
1334 $__git_fetch_options
1339 __git_complete_remote_or_refspec
1344 local cur="${COMP_WORDS[COMP_CWORD]}"
1345 case "${COMP_WORDS[COMP_CWORD-1]}" in
1347 __gitcomp "$(__git_remotes)"
1352 __gitcomp "$(__git_remotes)" "" "${cur##--repo=}"
1357 --all --mirror --tags --dry-run --force --verbose
1358 --receive-pack= --repo=
1363 __git_complete_remote_or_refspec
1368 local cur="${COMP_WORDS[COMP_CWORD]}" dir="$(__gitdir)"
1369 if [ -d "$dir"/rebase-apply ] || [ -d "$dir"/rebase-merge ]; then
1370 __gitcomp "--continue --skip --abort"
1373 __git_complete_strategy && return
1376 __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
1381 --onto --merge --strategy --interactive
1382 --preserve-merges --stat --no-stat
1383 --committer-date-is-author-date --ignore-date
1384 --ignore-whitespace --whitespace=
1390 __gitcomp "$(__git_refs)"
1393 __git_send_email_confirm_options="always never auto cc compose"
1394 __git_send_email_suppresscc_options="author self cc bodycc sob cccmd body all"
1398 local cur="${COMP_WORDS[COMP_CWORD]}"
1402 $__git_send_email_confirm_options
1403 " "" "${cur##--confirm=}"
1408 $__git_send_email_suppresscc_options
1409 " "" "${cur##--suppress-cc=}"
1413 --smtp-encryption=*)
1414 __gitcomp "ssl tls" "" "${cur##--smtp-encryption=}"
1418 __gitcomp "--annotate --bcc --cc --cc-cmd --chain-reply-to
1419 --compose --confirm= --dry-run --envelope-sender
1421 --in-reply-to --no-chain-reply-to --no-signed-off-by-cc
1422 --no-suppress-from --no-thread --quiet
1423 --signed-off-by-cc --smtp-pass --smtp-server
1424 --smtp-server-port --smtp-encryption= --smtp-user
1425 --subject --suppress-cc= --suppress-from --thread --to
1426 --validate --no-validate"
1433 __git_config_get_set_variables ()
1435 local prevword word config_file= c=$COMP_CWORD
1436 while [ $c -gt 1 ]; do
1437 word="${COMP_WORDS[c]}"
1439 --global|--system|--file=*)
1444 config_file="$word $prevword"
1452 git --git-dir="$(__gitdir)" config $config_file --list 2>/dev/null |
1465 local cur="${COMP_WORDS[COMP_CWORD]}"
1466 local prv="${COMP_WORDS[COMP_CWORD-1]}"
1469 __gitcomp "$(__git_remotes)"
1473 __gitcomp "$(__git_refs)"
1477 local remote="${prv#remote.}"
1478 remote="${remote%.fetch}"
1479 __gitcomp "$(__git_refs_remotes "$remote")"
1483 local remote="${prv#remote.}"
1484 remote="${remote%.push}"
1485 __gitcomp "$(git --git-dir="$(__gitdir)" \
1486 for-each-ref --format='%(refname):%(refname)' \
1490 pull.twohead|pull.octopus)
1491 __git_compute_merge_strategies
1492 __gitcomp "$__git_merge_strategies"
1495 color.branch|color.diff|color.interactive|\
1496 color.showbranch|color.status|color.ui)
1497 __gitcomp "always never auto"
1501 __gitcomp "false true"
1506 normal black red green yellow blue magenta cyan white
1507 bold dim ul blink reverse
1512 __gitcomp "man info web html"
1516 __gitcomp "$__git_log_date_formats"
1519 sendemail.aliasesfiletype)
1520 __gitcomp "mutt mailrc pine elm gnus"
1524 __gitcomp "$__git_send_email_confirm_options"
1527 sendemail.suppresscc)
1528 __gitcomp "$__git_send_email_suppresscc_options"
1531 --get|--get-all|--unset|--unset-all)
1532 __gitcomp "$(__git_config_get_set_variables)"
1543 --global --system --file=
1544 --list --replace-all
1545 --get --get-all --get-regexp
1546 --add --unset --unset-all
1547 --remove-section --rename-section
1552 local pfx="${cur%.*}."
1554 __gitcomp "remote merge mergeoptions rebase" "$pfx" "$cur"
1558 local pfx="${cur%.*}."
1560 __gitcomp "$(__git_heads)" "$pfx" "$cur" "."
1564 local pfx="${cur%.*}."
1567 argprompt cmd confirm needsfile noconsole norescan
1568 prompt revprompt revunmerged title
1573 local pfx="${cur%.*}."
1575 __gitcomp "cmd path" "$pfx" "$cur"
1579 local pfx="${cur%.*}."
1581 __gitcomp "cmd path" "$pfx" "$cur"
1585 local pfx="${cur%.*}."
1587 __gitcomp "cmd path trustExitCode" "$pfx" "$cur"
1591 local pfx="${cur%.*}."
1593 __git_compute_all_commands
1594 __gitcomp "$__git_all_commands" "$pfx" "$cur"
1598 local pfx="${cur%.*}."
1601 url proxy fetch push mirror skipDefaultUpdate
1602 receivepack uploadpack tagopt pushurl
1607 local pfx="${cur%.*}."
1609 __gitcomp "$(__git_remotes)" "$pfx" "$cur" "."
1613 local pfx="${cur%.*}."
1615 __gitcomp "insteadOf pushInsteadOf" "$pfx" "$cur"
1622 apply.ignorewhitespace
1624 branch.autosetupmerge
1625 branch.autosetuprebase
1628 color.branch.current
1639 color.diff.whitespace
1644 color.interactive.header
1645 color.interactive.help
1646 color.interactive.prompt
1651 color.status.changed
1653 color.status.nobranch
1654 color.status.untracked
1655 color.status.updated
1662 core.deltaBaseCacheLimit
1666 core.fsyncobjectfiles
1668 core.ignoreCygwinFSTricks
1670 core.logAllRefUpdates
1671 core.loosecompression
1673 core.packedGitWindowSize
1675 core.preferSymlinkRefs
1678 core.repositoryFormatVersion
1680 core.sharedRepository
1683 core.warnAmbiguousRefs
1686 diff.autorefreshindex
1692 diff.suppressBlankEmpty
1704 format.subjectprefix
1713 gc.reflogexpireunreachable
1717 gitcvs.commitmsgannotation
1718 gitcvs.dbTableNamePrefix
1729 gui.copyblamethreshold
1733 gui.matchtrackingbranch
1734 gui.newbranchtemplate
1735 gui.pruneduringfetch
1736 gui.spellingdictionary
1752 i18n.logOutputEncoding
1757 imap.preformattedHTML
1766 interactive.singlekey
1779 mergetool.keepBackup
1782 pack.deltaCacheLimit
1795 receive.denyCurrentBranch
1797 receive.denyNonFastForwards
1800 repack.usedeltabaseoffset
1803 sendemail.aliasesfile
1804 sendemail.aliasesfiletype
1808 sendemail.chainreplyto
1810 sendemail.envelopesender
1812 sendemail.signedoffbycc
1813 sendemail.smtpencryption
1815 sendemail.smtpserver
1816 sendemail.smtpserverport
1818 sendemail.suppresscc
1819 sendemail.suppressfrom
1824 status.relativePaths
1825 status.showUntrackedFiles
1827 transfer.unpackLimit
1839 local subcommands="add rename rm show prune update set-head"
1840 local subcommand="$(__git_find_on_cmdline "$subcommands")"
1841 if [ -z "$subcommand" ]; then
1842 __gitcomp "$subcommands"
1846 case "$subcommand" in
1847 rename|rm|show|prune)
1848 __gitcomp "$(__git_remotes)"
1851 local i c='' IFS=$'\n'
1852 for i in $(git --git-dir="$(__gitdir)" config --get-regexp "remotes\..*" 2>/dev/null); do
1866 __gitcomp "$(__git_refs)"
1871 __git_has_doubledash && return
1873 local cur="${COMP_WORDS[COMP_CWORD]}"
1876 __gitcomp "--merge --mixed --hard --soft --patch"
1880 __gitcomp "$(__git_refs)"
1885 local cur="${COMP_WORDS[COMP_CWORD]}"
1888 __gitcomp "--edit --mainline --no-edit --no-commit --signoff"
1892 __gitcomp "$(__git_refs)"
1897 __git_has_doubledash && return
1899 local cur="${COMP_WORDS[COMP_CWORD]}"
1902 __gitcomp "--cached --dry-run --ignore-unmatch --quiet"
1911 __git_has_doubledash && return
1913 local cur="${COMP_WORDS[COMP_CWORD]}"
1917 $__git_log_common_options
1918 $__git_log_shortlog_options
1919 --numbered --summary
1924 __git_complete_revlist
1929 __git_has_doubledash && return
1931 local cur="${COMP_WORDS[COMP_CWORD]}"
1934 __gitcomp "$__git_log_pretty_formats
1935 " "" "${cur##--pretty=}"
1939 __gitcomp "$__git_log_pretty_formats
1940 " "" "${cur##--format=}"
1944 __gitcomp "--pretty= --format= --abbrev-commit --oneline
1945 $__git_diff_common_options
1955 local cur="${COMP_WORDS[COMP_CWORD]}"
1959 --all --remotes --topo-order --current --more=
1960 --list --independent --merge-base --no-name
1962 --sha1-name --sparse --topics --reflog
1967 __git_complete_revlist
1972 local cur="${COMP_WORDS[COMP_CWORD]}"
1973 local save_opts='--keep-index --no-keep-index --quiet --patch'
1974 local subcommands='save list show apply clear drop pop create branch'
1975 local subcommand="$(__git_find_on_cmdline "$subcommands")"
1976 if [ -z "$subcommand" ]; then
1979 __gitcomp "$save_opts"
1982 if [ -z "$(__git_find_on_cmdline "$save_opts")" ]; then
1983 __gitcomp "$subcommands"
1990 case "$subcommand,$cur" in
1992 __gitcomp "$save_opts"
1995 __gitcomp "--index --quiet"
1997 show,--*|drop,--*|branch,--*)
2000 show,*|apply,*|drop,*|pop,*|branch,*)
2001 __gitcomp "$(git --git-dir="$(__gitdir)" stash list \
2002 | sed -n -e 's/:.*//p')"
2013 __git_has_doubledash && return
2015 local subcommands="add status init update summary foreach sync"
2016 if [ -z "$(__git_find_on_cmdline "$subcommands")" ]; then
2017 local cur="${COMP_WORDS[COMP_CWORD]}"
2020 __gitcomp "--quiet --cached"
2023 __gitcomp "$subcommands"
2033 init fetch clone rebase dcommit log find-rev
2034 set-tree commit-diff info create-ignore propget
2035 proplist show-ignore show-externals branch tag blame
2036 migrate mkdirs reset gc
2038 local subcommand="$(__git_find_on_cmdline "$subcommands")"
2039 if [ -z "$subcommand" ]; then
2040 __gitcomp "$subcommands"
2042 local remote_opts="--username= --config-dir= --no-auth-cache"
2044 --follow-parent --authors-file= --repack=
2045 --no-metadata --use-svm-props --use-svnsync-props
2046 --log-window-size= --no-checkout --quiet
2047 --repack-flags --use-log-author --localtime
2048 --ignore-paths= $remote_opts
2051 --template= --shared= --trunk= --tags=
2052 --branches= --stdlayout --minimize-url
2053 --no-metadata --use-svm-props --use-svnsync-props
2054 --rewrite-root= --prefix= --use-log-author
2055 --add-author-from $remote_opts
2058 --edit --rmdir --find-copies-harder --copy-similarity=
2061 local cur="${COMP_WORDS[COMP_CWORD]}"
2062 case "$subcommand,$cur" in
2064 __gitcomp "--revision= --fetch-all $fc_opts"
2067 __gitcomp "--revision= $fc_opts $init_opts"
2070 __gitcomp "$init_opts"
2074 --merge --strategy= --verbose --dry-run
2075 --fetch-all --no-rebase --commit-url
2076 --revision $cmt_opts $fc_opts
2080 __gitcomp "--stdin $cmt_opts $fc_opts"
2082 create-ignore,--*|propget,--*|proplist,--*|show-ignore,--*|\
2083 show-externals,--*|mkdirs,--*)
2084 __gitcomp "--revision="
2088 --limit= --revision= --verbose --incremental
2089 --oneline --show-commit --non-recursive
2090 --authors-file= --color
2095 --merge --verbose --strategy= --local
2096 --fetch-all --dry-run $fc_opts
2100 __gitcomp "--message= --file= --revision= $cmt_opts"
2106 __gitcomp "--dry-run --message --tag"
2109 __gitcomp "--dry-run --message"
2112 __gitcomp "--git-format"
2116 --config-dir= --ignore-paths= --minimize
2117 --no-auth-cache --username=
2121 __gitcomp "--revision= --parent"
2133 while [ $c -lt $COMP_CWORD ]; do
2134 i="${COMP_WORDS[c]}"
2137 __gitcomp "$(__git_tags)"
2147 case "${COMP_WORDS[COMP_CWORD-1]}" in
2153 __gitcomp "$(__git_tags)"
2159 __gitcomp "$(__git_refs)"
2166 local i c=1 command __git_dir
2168 while [ $c -lt $COMP_CWORD ]; do
2169 i="${COMP_WORDS[c]}"
2171 --git-dir=*) __git_dir="${i#--git-dir=}" ;;
2172 --bare) __git_dir="." ;;
2173 --version|-p|--paginate) ;;
2174 --help) command="help"; break ;;
2175 *) command="$i"; break ;;
2180 if [ -z "$command" ]; then
2181 case "${COMP_WORDS[COMP_CWORD]}" in
2194 *) __git_compute_porcelain_commands
2195 __gitcomp "$__git_porcelain_commands $(__git_aliases)" ;;
2200 local expansion=$(__git_aliased_command "$command")
2201 [ "$expansion" ] && command="$expansion"
2206 apply) _git_apply ;;
2207 archive) _git_archive ;;
2208 bisect) _git_bisect ;;
2209 bundle) _git_bundle ;;
2210 branch) _git_branch ;;
2211 checkout) _git_checkout ;;
2212 cherry) _git_cherry ;;
2213 cherry-pick) _git_cherry_pick ;;
2214 clean) _git_clean ;;
2215 clone) _git_clone ;;
2216 commit) _git_commit ;;
2217 config) _git_config ;;
2218 describe) _git_describe ;;
2220 difftool) _git_difftool ;;
2221 fetch) _git_fetch ;;
2222 format-patch) _git_format_patch ;;
2229 ls-files) _git_ls_files ;;
2230 ls-remote) _git_ls_remote ;;
2231 ls-tree) _git_ls_tree ;;
2233 mergetool) _git_mergetool;;
2234 merge-base) _git_merge_base ;;
2236 name-rev) _git_name_rev ;;
2237 notes) _git_notes ;;
2240 rebase) _git_rebase ;;
2241 remote) _git_remote ;;
2242 replace) _git_replace ;;
2243 reset) _git_reset ;;
2244 revert) _git_revert ;;
2246 send-email) _git_send_email ;;
2247 shortlog) _git_shortlog ;;
2249 show-branch) _git_show_branch ;;
2250 stash) _git_stash ;;
2252 submodule) _git_submodule ;;
2255 whatchanged) _git_log ;;
2262 __git_has_doubledash && return
2264 local cur="${COMP_WORDS[COMP_CWORD]}"
2265 local g="$(__gitdir)"
2267 if [ -f "$g/MERGE_HEAD" ]; then
2273 $__git_log_common_options
2274 $__git_log_gitk_options
2280 __git_complete_revlist
2283 complete -o bashdefault -o default -o nospace -F _git git 2>/dev/null \
2284 || complete -o default -o nospace -F _git git
2285 complete -o bashdefault -o default -o nospace -F _gitk gitk 2>/dev/null \
2286 || complete -o default -o nospace -F _gitk gitk
2288 # The following are necessary only for Cygwin, and only are needed
2289 # when the user has tab-completed the executable name and consequently
2290 # included the '.exe' suffix.
2292 if [ Cygwin = "$(uname -o 2>/dev/null)" ]; then
2293 complete -o bashdefault -o default -o nospace -F _git git.exe 2>/dev/null \
2294 || complete -o default -o nospace -F _git git.exe