3 # bash 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) Added the following line to your .bashrc:
22 # source ~/.git-completion.sh
24 # 3) You may want to make sure the git executable is available
25 # in your PATH before this script is sourced, as some caching
26 # is performed while the script loads. If git isn't found
27 # at source time then all lookups will be done on demand,
28 # which may be slightly slower.
30 # 4) Consider changing your PS1 to also show the current branch:
31 # PS1='[\u@\h \W$(__git_ps1 " (%s)")]\$ '
33 # The argument to __git_ps1 will be displayed only if you
34 # are currently in a git repository. The %s token will be
35 # the name of the current branch.
37 # In addition, if you set GIT_PS1_SHOWDIRTYSTATE to a nonempty
38 # value, unstaged (*) and staged (+) changes will be shown next
39 # to the branch name. You can configure this per-repository
40 # with the bash.showDirtyState variable, which defaults to true
41 # once GIT_PS1_SHOWDIRTYSTATE is enabled.
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 [ -d "$g/rebase-apply" ]; then
88 if [ -f "$g/rebase-apply/rebasing" ]; then
90 elif [ -f "$g/rebase-apply/applying" ]; then
95 b="$(git symbolic-ref HEAD 2>/dev/null)"
96 elif [ -f "$g/rebase-merge/interactive" ]; then
98 b="$(cat "$g/rebase-merge/head-name")"
99 elif [ -d "$g/rebase-merge" ]; then
101 b="$(cat "$g/rebase-merge/head-name")"
102 elif [ -f "$g/MERGE_HEAD" ]; then
104 b="$(git symbolic-ref HEAD 2>/dev/null)"
106 if [ -f "$g/BISECT_LOG" ]; then
109 if ! b="$(git symbolic-ref HEAD 2>/dev/null)"; then
110 if ! b="$(git describe --exact-match HEAD 2>/dev/null)"; then
111 if [ -r "$g/HEAD" ]; then
112 b="$(cut -c1-7 "$g/HEAD")..."
122 if [ "true" = "$(git rev-parse --is-inside-git-dir 2>/dev/null)" ]; then
123 if [ "true" = "$(git config --bool core.bare 2>/dev/null)" ]; then
128 elif [ "true" = "$(git rev-parse --is-inside-work-tree 2>/dev/null)" ]; then
129 if [ -n "${GIT_PS1_SHOWDIRTYSTATE-}" ]; then
130 if [ "$(git config --bool bash.showDirtyState)" != "false" ]; then
131 git diff --no-ext-diff --ignore-submodules \
132 --quiet --exit-code || w="*"
133 if git rev-parse --quiet --verify HEAD >/dev/null; then
134 git diff-index --cached --quiet \
135 --ignore-submodules HEAD -- || i="+"
144 if [ -n "${1-}" ]; then
145 printf "$1" "$c${b##refs/heads/}$w$i$r"
147 printf " (%s)" "$c${b##refs/heads/}$w$i$r"
153 # __gitcomp_1 requires 2 arguments
156 local c IFS=' '$'\t'$'\n'
159 --*=*) printf %s$'\n' "$c$2" ;;
160 *.) printf %s$'\n' "$c$2" ;;
161 *) printf %s$'\n' "$c$2 " ;;
166 # __gitcomp accepts 1, 2, 3, or 4 arguments
167 # generates completion reply with compgen
170 local cur="${COMP_WORDS[COMP_CWORD]}"
171 if [ $# -gt 2 ]; then
180 COMPREPLY=($(compgen -P "${2-}" \
181 -W "$(__gitcomp_1 "${1-}" "${4-}")" \
187 # __git_heads accepts 0 or 1 arguments (to pass to __gitdir)
190 local cmd i is_hash=y dir="$(__gitdir "${1-}")"
191 if [ -d "$dir" ]; then
192 git --git-dir="$dir" for-each-ref --format='%(refname:short)' \
196 for i in $(git ls-remote "${1-}" 2>/dev/null); do
197 case "$is_hash,$i" in
200 n,refs/heads/*) is_hash=y; echo "${i#refs/heads/}" ;;
201 n,*) is_hash=y; echo "$i" ;;
206 # __git_tags accepts 0 or 1 arguments (to pass to __gitdir)
209 local cmd i is_hash=y dir="$(__gitdir "${1-}")"
210 if [ -d "$dir" ]; then
211 git --git-dir="$dir" for-each-ref --format='%(refname:short)' \
215 for i in $(git ls-remote "${1-}" 2>/dev/null); do
216 case "$is_hash,$i" in
219 n,refs/tags/*) is_hash=y; echo "${i#refs/tags/}" ;;
220 n,*) is_hash=y; echo "$i" ;;
225 # __git_refs accepts 0 or 1 arguments (to pass to __gitdir)
228 local i is_hash=y dir="$(__gitdir "${1-}")"
229 local cur="${COMP_WORDS[COMP_CWORD]}" format refs
230 if [ -d "$dir" ]; then
237 if [ -e "$dir/HEAD" ]; then echo HEAD; fi
238 format="refname:short"
239 refs="refs/tags refs/heads refs/remotes"
242 git --git-dir="$dir" for-each-ref --format="%($format)" \
246 for i in $(git ls-remote "$dir" 2>/dev/null); do
247 case "$is_hash,$i" in
250 n,refs/tags/*) is_hash=y; echo "${i#refs/tags/}" ;;
251 n,refs/heads/*) is_hash=y; echo "${i#refs/heads/}" ;;
252 n,refs/remotes/*) is_hash=y; echo "${i#refs/remotes/}" ;;
253 n,*) is_hash=y; echo "$i" ;;
258 # __git_refs2 requires 1 argument (to pass to __git_refs)
262 for i in $(__git_refs "$1"); do
267 # __git_refs_remotes requires 1 argument (to pass to ls-remote)
268 __git_refs_remotes ()
270 local cmd i is_hash=y
271 for i in $(git ls-remote "$1" 2>/dev/null); do
272 case "$is_hash,$i" in
275 echo "$i:refs/remotes/$1/${i#refs/heads/}"
279 n,refs/tags/*) is_hash=y;;
287 local i ngoff IFS=$'\n' d="$(__gitdir)"
288 shopt -q nullglob || ngoff=1
290 for i in "$d/remotes"/*; do
291 echo ${i#$d/remotes/}
293 [ "$ngoff" ] && shopt -u nullglob
294 for i in $(git --git-dir="$d" config --list); do
304 __git_merge_strategies ()
306 if [ -n "${__git_merge_strategylist-}" ]; then
307 echo "$__git_merge_strategylist"
310 git merge -s help 2>&1 |
311 sed -n -e '/[Aa]vailable strategies are: /,/^$/{
319 __git_merge_strategylist=
320 __git_merge_strategylist=$(__git_merge_strategies 2>/dev/null)
322 __git_complete_file ()
324 local pfx ls ref cur="${COMP_WORDS[COMP_CWORD]}"
341 case "$COMP_WORDBREAKS" in
343 *) pfx="$ref:$pfx" ;;
347 COMPREPLY=($(compgen -P "$pfx" \
348 -W "$(git --git-dir="$(__gitdir)" ls-tree "$ls" \
349 | sed '/^100... blob /{
365 __gitcomp "$(__git_refs)"
370 __git_complete_revlist ()
372 local pfx cur="${COMP_WORDS[COMP_CWORD]}"
377 __gitcomp "$(__git_refs)" "$pfx" "$cur"
382 __gitcomp "$(__git_refs)" "$pfx" "$cur"
385 __gitcomp "$(__git_refs)"
390 __git_complete_remote_or_refspec ()
392 local cmd="${COMP_WORDS[1]}"
393 local cur="${COMP_WORDS[COMP_CWORD]}"
394 local i c=2 remote="" pfx="" lhs=1 no_complete_refspec=0
395 while [ $c -lt $COMP_CWORD ]; do
398 --all|--mirror) [ "$cmd" = "push" ] && no_complete_refspec=1 ;;
400 *) remote="$i"; break ;;
404 if [ -z "$remote" ]; then
405 __gitcomp "$(__git_remotes)"
408 if [ $no_complete_refspec = 1 ]; then
412 [ "$remote" = "." ] && remote=
415 case "$COMP_WORDBREAKS" in
417 *) pfx="${cur%%:*}:" ;;
429 if [ $lhs = 1 ]; then
430 __gitcomp "$(__git_refs2 "$remote")" "$pfx" "$cur"
432 __gitcomp "$(__git_refs)" "$pfx" "$cur"
436 if [ $lhs = 1 ]; then
437 __gitcomp "$(__git_refs "$remote")" "$pfx" "$cur"
439 __gitcomp "$(__git_refs)" "$pfx" "$cur"
443 if [ $lhs = 1 ]; then
444 __gitcomp "$(__git_refs)" "$pfx" "$cur"
446 __gitcomp "$(__git_refs "$remote")" "$pfx" "$cur"
452 __git_complete_strategy ()
454 case "${COMP_WORDS[COMP_CWORD-1]}" in
456 __gitcomp "$(__git_merge_strategies)"
459 local cur="${COMP_WORDS[COMP_CWORD]}"
462 __gitcomp "$(__git_merge_strategies)" "" "${cur##--strategy=}"
469 __git_all_commands ()
471 if [ -n "${__git_all_commandlist-}" ]; then
472 echo "$__git_all_commandlist"
476 for i in $(git help -a|egrep '^ ')
479 *--*) : helper pattern;;
484 __git_all_commandlist=
485 __git_all_commandlist="$(__git_all_commands 2>/dev/null)"
487 __git_porcelain_commands ()
489 if [ -n "${__git_porcelain_commandlist-}" ]; then
490 echo "$__git_porcelain_commandlist"
494 for i in "help" $(__git_all_commands)
497 *--*) : helper pattern;;
498 applymbox) : ask gittus;;
499 applypatch) : ask gittus;;
500 archimport) : import;;
501 cat-file) : plumbing;;
502 check-attr) : plumbing;;
503 check-ref-format) : plumbing;;
504 checkout-index) : plumbing;;
505 commit-tree) : plumbing;;
506 count-objects) : infrequent;;
507 cvsexportcommit) : export;;
508 cvsimport) : import;;
509 cvsserver) : daemon;;
511 diff-files) : plumbing;;
512 diff-index) : plumbing;;
513 diff-tree) : plumbing;;
514 fast-import) : import;;
515 fast-export) : export;;
516 fsck-objects) : plumbing;;
517 fetch-pack) : plumbing;;
518 fmt-merge-msg) : plumbing;;
519 for-each-ref) : plumbing;;
520 hash-object) : plumbing;;
521 http-*) : transport;;
522 index-pack) : plumbing;;
523 init-db) : deprecated;;
524 local-fetch) : plumbing;;
525 lost-found) : infrequent;;
526 ls-files) : plumbing;;
527 ls-remote) : plumbing;;
528 ls-tree) : plumbing;;
529 mailinfo) : plumbing;;
530 mailsplit) : plumbing;;
531 merge-*) : plumbing;;
534 pack-objects) : plumbing;;
535 pack-redundant) : plumbing;;
536 pack-refs) : plumbing;;
537 parse-remote) : plumbing;;
538 patch-id) : plumbing;;
539 peek-remote) : plumbing;;
541 prune-packed) : plumbing;;
542 quiltimport) : import;;
543 read-tree) : plumbing;;
544 receive-pack) : plumbing;;
546 repo-config) : deprecated;;
548 rev-list) : plumbing;;
549 rev-parse) : plumbing;;
550 runstatus) : plumbing;;
551 sh-setup) : internal;;
553 show-ref) : plumbing;;
554 send-pack) : plumbing;;
555 show-index) : plumbing;;
557 stripspace) : plumbing;;
558 symbolic-ref) : plumbing;;
559 tar-tree) : deprecated;;
560 unpack-file) : plumbing;;
561 unpack-objects) : plumbing;;
562 update-index) : plumbing;;
563 update-ref) : plumbing;;
564 update-server-info) : daemon;;
565 upload-archive) : plumbing;;
566 upload-pack) : plumbing;;
567 write-tree) : plumbing;;
569 verify-pack) : infrequent;;
570 verify-tag) : plumbing;;
575 __git_porcelain_commandlist=
576 __git_porcelain_commandlist="$(__git_porcelain_commands 2>/dev/null)"
581 for i in $(git --git-dir="$(__gitdir)" config --list); do
591 # __git_aliased_command requires 1 argument
592 __git_aliased_command ()
594 local word cmdline=$(git --git-dir="$(__gitdir)" \
595 config --get "alias.$1")
596 for word in $cmdline; do
597 if [ "${word##-*}" ]; then
604 # __git_find_subcommand requires 1 argument
605 __git_find_subcommand ()
607 local word subcommand c=1
609 while [ $c -lt $COMP_CWORD ]; do
610 word="${COMP_WORDS[c]}"
611 for subcommand in $1; do
612 if [ "$subcommand" = "$word" ]; then
621 __git_has_doubledash ()
624 while [ $c -lt $COMP_CWORD ]; do
625 if [ "--" = "${COMP_WORDS[c]}" ]; then
633 __git_whitespacelist="nowarn warn error error-all fix"
637 local cur="${COMP_WORDS[COMP_CWORD]}" dir="$(__gitdir)"
638 if [ -d "$dir"/rebase-apply ]; then
639 __gitcomp "--skip --resolved --abort"
644 __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
649 --signoff --utf8 --binary --3way --interactive
659 local cur="${COMP_WORDS[COMP_CWORD]}"
662 __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
667 --stat --numstat --summary --check --index
668 --cached --index-info --reverse --reject --unidiff-zero
669 --apply --no-add --exclude=
670 --whitespace= --inaccurate-eof --verbose
679 __git_has_doubledash && return
681 local cur="${COMP_WORDS[COMP_CWORD]}"
685 --interactive --refresh --patch --update --dry-run
686 --ignore-errors --intent-to-add
695 local cur="${COMP_WORDS[COMP_CWORD]}"
698 __gitcomp "$(git archive --list)" "" "${cur##--format=}"
702 __gitcomp "$(__git_remotes)" "" "${cur##--remote=}"
707 --format= --list --verbose
708 --prefix= --remote= --exec=
718 __git_has_doubledash && return
720 local subcommands="start bad good skip reset visualize replay log run"
721 local subcommand="$(__git_find_subcommand "$subcommands")"
722 if [ -z "$subcommand" ]; then
723 __gitcomp "$subcommands"
727 case "$subcommand" in
729 __gitcomp "$(__git_refs)"
739 local i c=1 only_local_ref="n" has_r="n"
741 while [ $c -lt $COMP_CWORD ]; do
744 -d|-m) only_local_ref="y" ;;
750 case "${COMP_WORDS[COMP_CWORD]}" in
753 --color --no-color --verbose --abbrev= --no-abbrev
754 --track --no-track --contains --merged --no-merged
758 if [ $only_local_ref = "y" -a $has_r = "n" ]; then
759 __gitcomp "$(__git_heads)"
761 __gitcomp "$(__git_refs)"
769 local cmd="${COMP_WORDS[2]}"
770 case "$COMP_CWORD" in
772 __gitcomp "create list-heads verify unbundle"
780 __git_complete_revlist
789 __git_has_doubledash && return
791 __gitcomp "$(__git_refs)"
796 __gitcomp "$(__git_refs)"
801 local cur="${COMP_WORDS[COMP_CWORD]}"
804 __gitcomp "--edit --no-commit"
807 __gitcomp "$(__git_refs)"
814 __git_has_doubledash && return
816 local cur="${COMP_WORDS[COMP_CWORD]}"
819 __gitcomp "--dry-run --quiet"
828 local cur="${COMP_WORDS[COMP_CWORD]}"
853 __git_has_doubledash && return
855 local cur="${COMP_WORDS[COMP_CWORD]}"
859 --all --author= --signoff --verify --no-verify
860 --edit --amend --include --only --interactive
869 local cur="${COMP_WORDS[COMP_CWORD]}"
873 --all --tags --contains --abbrev= --candidates=
874 --exact-match --debug --long --match --always
878 __gitcomp "$(__git_refs)"
881 __git_diff_common_options="--stat --numstat --shortstat --summary
882 --patch-with-stat --name-only --name-status --color
883 --no-color --color-words --no-renames --check
884 --full-index --binary --abbrev --diff-filter=
886 --text --ignore-space-at-eol --ignore-space-change
887 --ignore-all-space --exit-code --quiet --ext-diff
889 --no-prefix --src-prefix= --dst-prefix=
890 --inter-hunk-context=
897 __git_has_doubledash && return
899 local cur="${COMP_WORDS[COMP_CWORD]}"
902 __gitcomp "--cached --staged --pickaxe-all --pickaxe-regex
903 --base --ours --theirs
904 $__git_diff_common_options
912 __git_fetch_options="
913 --quiet --verbose --append --upload-pack --force --keep --depth=
919 local cur="${COMP_WORDS[COMP_CWORD]}"
922 __gitcomp "$__git_fetch_options"
926 __git_complete_remote_or_refspec
931 local cur="${COMP_WORDS[COMP_CWORD]}"
935 --stdout --attach --thread
937 --numbered --start-number
942 --full-index --binary
945 --no-prefix --src-prefix= --dst-prefix=
946 --inline --suffix= --ignore-if-in-upstream
952 __git_complete_revlist
957 local cur="${COMP_WORDS[COMP_CWORD]}"
961 --tags --root --unreachable --cache --no-reflogs --full
962 --strict --verbose --lost-found
972 local cur="${COMP_WORDS[COMP_CWORD]}"
975 __gitcomp "--prune --aggressive"
984 __git_has_doubledash && return
986 local cur="${COMP_WORDS[COMP_CWORD]}"
991 --text --ignore-case --word-regexp --invert-match
993 --extended-regexp --basic-regexp --fixed-strings
994 --files-with-matches --name-only
995 --files-without-match
997 --and --or --not --all-match
1007 local cur="${COMP_WORDS[COMP_CWORD]}"
1010 __gitcomp "--all --info --man --web"
1014 __gitcomp "$(__git_all_commands)
1015 attributes cli core-tutorial cvs-migration
1016 diffcore gitk glossary hooks ignore modules
1017 repository-layout tutorial tutorial-2
1024 local cur="${COMP_WORDS[COMP_CWORD]}"
1028 false true umask group all world everybody
1029 " "" "${cur##--shared=}"
1033 __gitcomp "--quiet --bare --template= --shared --shared="
1042 __git_has_doubledash && return
1044 local cur="${COMP_WORDS[COMP_CWORD]}"
1047 __gitcomp "--cached --deleted --modified --others --ignored
1048 --stage --directory --no-empty-directory --unmerged
1049 --killed --exclude= --exclude-from=
1050 --exclude-per-directory= --exclude-standard
1051 --error-unmatch --with-tree= --full-name
1052 --abbrev --ignored --exclude-per-directory
1062 __gitcomp "$(__git_remotes)"
1070 # Options that go well for log, shortlog and gitk
1071 __git_log_common_options="
1073 --branches --tags --remotes
1074 --first-parent --no-merges
1076 --max-age= --since= --after=
1077 --min-age= --until= --before=
1079 # Options that go well for log and gitk (not shortlog)
1080 __git_log_gitk_options="
1081 --dense --sparse --full-history
1082 --simplify-merges --simplify-by-decoration
1085 # Options that go well for log and shortlog (not gitk)
1086 __git_log_shortlog_options="
1087 --author= --committer= --grep=
1091 __git_log_pretty_formats="oneline short medium full fuller email raw format:"
1095 __git_has_doubledash && return
1097 local cur="${COMP_WORDS[COMP_CWORD]}"
1098 local g="$(git rev-parse --git-dir 2>/dev/null)"
1100 if [ -f $g/MERGE_HEAD ]; then
1105 __gitcomp "$__git_log_pretty_formats
1106 " "" "${cur##--pretty=}"
1110 __gitcomp "$__git_log_pretty_formats
1111 " "" "${cur##--format=}"
1116 relative iso8601 rfc2822 short local default
1117 " "" "${cur##--date=}"
1122 $__git_log_common_options
1123 $__git_log_shortlog_options
1124 $__git_log_gitk_options
1125 --root --topo-order --date-order --reverse
1127 --abbrev-commit --abbrev=
1128 --relative-date --date=
1129 --pretty= --format= --oneline
1134 --parents --children
1136 $__git_diff_common_options
1137 --pickaxe-all --pickaxe-regex
1142 __git_complete_revlist
1145 __git_merge_options="
1146 --no-commit --no-stat --log --no-log --squash --strategy
1147 --commit --stat --no-squash --ff --no-ff
1152 __git_complete_strategy && return
1154 local cur="${COMP_WORDS[COMP_CWORD]}"
1157 __gitcomp "$__git_merge_options"
1160 __gitcomp "$(__git_refs)"
1165 local cur="${COMP_WORDS[COMP_CWORD]}"
1169 kdiff3 tkdiff meld xxdiff emerge
1170 vimdiff gvimdiff ecmerge opendiff
1171 " "" "${cur##--tool=}"
1184 __gitcomp "$(__git_refs)"
1189 local cur="${COMP_WORDS[COMP_CWORD]}"
1192 __gitcomp "--dry-run"
1201 __gitcomp "--tags --all --stdin"
1206 __git_complete_strategy && return
1208 local cur="${COMP_WORDS[COMP_CWORD]}"
1212 --rebase --no-rebase
1213 $__git_merge_options
1214 $__git_fetch_options
1219 __git_complete_remote_or_refspec
1224 local cur="${COMP_WORDS[COMP_CWORD]}"
1225 case "${COMP_WORDS[COMP_CWORD-1]}" in
1227 __gitcomp "$(__git_remotes)"
1232 __gitcomp "$(__git_remotes)" "" "${cur##--repo=}"
1237 --all --mirror --tags --dry-run --force --verbose
1238 --receive-pack= --repo=
1243 __git_complete_remote_or_refspec
1248 local cur="${COMP_WORDS[COMP_CWORD]}" dir="$(__gitdir)"
1249 if [ -d "$dir"/rebase-apply ] || [ -d "$dir"/rebase-merge ]; then
1250 __gitcomp "--continue --skip --abort"
1253 __git_complete_strategy && return
1256 __gitcomp "--onto --merge --strategy --interactive"
1259 __gitcomp "$(__git_refs)"
1264 local cur="${COMP_WORDS[COMP_CWORD]}"
1267 __gitcomp "--bcc --cc --cc-cmd --chain-reply-to --compose
1268 --dry-run --envelope-sender --from --identity
1269 --in-reply-to --no-chain-reply-to --no-signed-off-by-cc
1270 --no-suppress-from --no-thread --quiet
1271 --signed-off-by-cc --smtp-pass --smtp-server
1272 --smtp-server-port --smtp-ssl --smtp-user --subject
1273 --suppress-cc --suppress-from --thread --to
1274 --validate --no-validate"
1283 local cur="${COMP_WORDS[COMP_CWORD]}"
1284 local prv="${COMP_WORDS[COMP_CWORD-1]}"
1287 __gitcomp "$(__git_remotes)"
1291 __gitcomp "$(__git_refs)"
1295 local remote="${prv#remote.}"
1296 remote="${remote%.fetch}"
1297 __gitcomp "$(__git_refs_remotes "$remote")"
1301 local remote="${prv#remote.}"
1302 remote="${remote%.push}"
1303 __gitcomp "$(git --git-dir="$(__gitdir)" \
1304 for-each-ref --format='%(refname):%(refname)' \
1308 pull.twohead|pull.octopus)
1309 __gitcomp "$(__git_merge_strategies)"
1312 color.branch|color.diff|color.interactive|color.status|color.ui)
1313 __gitcomp "always never auto"
1317 __gitcomp "false true"
1322 normal black red green yellow blue magenta cyan white
1323 bold dim ul blink reverse
1335 --global --system --file=
1336 --list --replace-all
1337 --get --get-all --get-regexp
1338 --add --unset --unset-all
1339 --remove-section --rename-section
1344 local pfx="${cur%.*}."
1346 __gitcomp "remote merge mergeoptions" "$pfx" "$cur"
1350 local pfx="${cur%.*}."
1352 __gitcomp "$(__git_heads)" "$pfx" "$cur" "."
1356 local pfx="${cur%.*}."
1359 url proxy fetch push mirror skipDefaultUpdate
1360 receivepack uploadpack tagopt
1365 local pfx="${cur%.*}."
1367 __gitcomp "$(__git_remotes)" "$pfx" "$cur" "."
1373 branch.autosetupmerge
1374 branch.autosetuprebase
1377 color.branch.current
1388 color.diff.whitespace
1390 color.interactive.header
1391 color.interactive.help
1392 color.interactive.prompt
1396 color.status.changed
1398 color.status.nobranch
1399 color.status.untracked
1400 color.status.updated
1406 core.deltaBaseCacheLimit
1410 core.fsyncobjectfiles
1412 core.ignoreCygwinFSTricks
1414 core.logAllRefUpdates
1415 core.loosecompression
1417 core.packedGitWindowSize
1419 core.preferSymlinkRefs
1422 core.repositoryFormatVersion
1424 core.sharedRepository
1427 core.warnAmbiguousRefs
1430 diff.autorefreshindex
1447 gc.reflogexpireunreachable
1451 gitcvs.dbTableNamePrefix
1461 gui.copyblamethreshold
1465 gui.matchtrackingbranch
1466 gui.newbranchtemplate
1467 gui.pruneduringfetch
1468 gui.spellingdictionary
1484 i18n.logOutputEncoding
1499 mergetool.keepBackup
1501 pack.deltaCacheLimit
1511 receive.denyCurrentBranch
1513 receive.denyNonFastForwards
1516 repack.usedeltabaseoffset
1520 status.relativePaths
1521 status.showUntrackedFiles
1523 transfer.unpackLimit
1534 local subcommands="add rename rm show prune update set-head"
1535 local subcommand="$(__git_find_subcommand "$subcommands")"
1536 if [ -z "$subcommand" ]; then
1537 __gitcomp "$subcommands"
1541 case "$subcommand" in
1542 rename|rm|show|prune)
1543 __gitcomp "$(__git_remotes)"
1546 local i c='' IFS=$'\n'
1547 for i in $(git --git-dir="$(__gitdir)" config --list); do
1565 __git_has_doubledash && return
1567 local cur="${COMP_WORDS[COMP_CWORD]}"
1570 __gitcomp "--merge --mixed --hard --soft"
1574 __gitcomp "$(__git_refs)"
1579 local cur="${COMP_WORDS[COMP_CWORD]}"
1582 __gitcomp "--edit --mainline --no-edit --no-commit --signoff"
1586 __gitcomp "$(__git_refs)"
1591 __git_has_doubledash && return
1593 local cur="${COMP_WORDS[COMP_CWORD]}"
1596 __gitcomp "--cached --dry-run --ignore-unmatch --quiet"
1605 __git_has_doubledash && return
1607 local cur="${COMP_WORDS[COMP_CWORD]}"
1611 $__git_log_common_options
1612 $__git_log_shortlog_options
1613 --numbered --summary
1618 __git_complete_revlist
1623 __git_has_doubledash && return
1625 local cur="${COMP_WORDS[COMP_CWORD]}"
1628 __gitcomp "$__git_log_pretty_formats
1629 " "" "${cur##--pretty=}"
1633 __gitcomp "$__git_log_pretty_formats
1634 " "" "${cur##--format=}"
1638 __gitcomp "--pretty= --format=
1639 $__git_diff_common_options
1649 local cur="${COMP_WORDS[COMP_CWORD]}"
1653 --all --remotes --topo-order --current --more=
1654 --list --independent --merge-base --no-name
1655 --sha1-name --topics --reflog
1660 __git_complete_revlist
1665 local subcommands='save list show apply clear drop pop create branch'
1666 local subcommand="$(__git_find_subcommand "$subcommands")"
1667 if [ -z "$subcommand" ]; then
1668 __gitcomp "$subcommands"
1670 local cur="${COMP_WORDS[COMP_CWORD]}"
1671 case "$subcommand,$cur" in
1673 __gitcomp "--keep-index"
1678 show,--*|drop,--*|pop,--*|branch,--*)
1681 show,*|apply,*|drop,*|pop,*|branch,*)
1682 __gitcomp "$(git --git-dir="$(__gitdir)" stash list \
1683 | sed -n -e 's/:.*//p')"
1694 __git_has_doubledash && return
1696 local subcommands="add status init update summary foreach sync"
1697 if [ -z "$(__git_find_subcommand "$subcommands")" ]; then
1698 local cur="${COMP_WORDS[COMP_CWORD]}"
1701 __gitcomp "--quiet --cached"
1704 __gitcomp "$subcommands"
1714 init fetch clone rebase dcommit log find-rev
1715 set-tree commit-diff info create-ignore propget
1716 proplist show-ignore show-externals branch tag blame
1719 local subcommand="$(__git_find_subcommand "$subcommands")"
1720 if [ -z "$subcommand" ]; then
1721 __gitcomp "$subcommands"
1723 local remote_opts="--username= --config-dir= --no-auth-cache"
1725 --follow-parent --authors-file= --repack=
1726 --no-metadata --use-svm-props --use-svnsync-props
1727 --log-window-size= --no-checkout --quiet
1728 --repack-flags --use-log-author --localtime
1729 --ignore-paths= $remote_opts
1732 --template= --shared= --trunk= --tags=
1733 --branches= --stdlayout --minimize-url
1734 --no-metadata --use-svm-props --use-svnsync-props
1735 --rewrite-root= --prefix= --use-log-author
1736 --add-author-from $remote_opts
1739 --edit --rmdir --find-copies-harder --copy-similarity=
1742 local cur="${COMP_WORDS[COMP_CWORD]}"
1743 case "$subcommand,$cur" in
1745 __gitcomp "--revision= --fetch-all $fc_opts"
1748 __gitcomp "--revision= $fc_opts $init_opts"
1751 __gitcomp "$init_opts"
1755 --merge --strategy= --verbose --dry-run
1756 --fetch-all --no-rebase --commit-url
1757 --revision $cmt_opts $fc_opts
1761 __gitcomp "--stdin $cmt_opts $fc_opts"
1763 create-ignore,--*|propget,--*|proplist,--*|show-ignore,--*|\
1765 __gitcomp "--revision="
1769 --limit= --revision= --verbose --incremental
1770 --oneline --show-commit --non-recursive
1771 --authors-file= --color
1776 --merge --verbose --strategy= --local
1777 --fetch-all --dry-run $fc_opts
1781 __gitcomp "--message= --file= --revision= $cmt_opts"
1787 __gitcomp "--dry-run --message --tag"
1790 __gitcomp "--dry-run --message"
1793 __gitcomp "--git-format"
1797 --config-dir= --ignore-paths= --minimize
1798 --no-auth-cache --username=
1811 while [ $c -lt $COMP_CWORD ]; do
1812 i="${COMP_WORDS[c]}"
1815 __gitcomp "$(__git_tags)"
1825 case "${COMP_WORDS[COMP_CWORD-1]}" in
1831 __gitcomp "$(__git_tags)"
1837 __gitcomp "$(__git_refs)"
1844 local i c=1 command __git_dir
1846 while [ $c -lt $COMP_CWORD ]; do
1847 i="${COMP_WORDS[c]}"
1849 --git-dir=*) __git_dir="${i#--git-dir=}" ;;
1850 --bare) __git_dir="." ;;
1851 --version|-p|--paginate) ;;
1852 --help) command="help"; break ;;
1853 *) command="$i"; break ;;
1858 if [ -z "$command" ]; then
1859 case "${COMP_WORDS[COMP_CWORD]}" in
1871 *) __gitcomp "$(__git_porcelain_commands) $(__git_aliases)" ;;
1876 local expansion=$(__git_aliased_command "$command")
1877 [ "$expansion" ] && command="$expansion"
1882 apply) _git_apply ;;
1883 archive) _git_archive ;;
1884 bisect) _git_bisect ;;
1885 bundle) _git_bundle ;;
1886 branch) _git_branch ;;
1887 checkout) _git_checkout ;;
1888 cherry) _git_cherry ;;
1889 cherry-pick) _git_cherry_pick ;;
1890 clean) _git_clean ;;
1891 clone) _git_clone ;;
1892 commit) _git_commit ;;
1893 config) _git_config ;;
1894 describe) _git_describe ;;
1896 fetch) _git_fetch ;;
1897 format-patch) _git_format_patch ;;
1904 ls-files) _git_ls_files ;;
1905 ls-remote) _git_ls_remote ;;
1906 ls-tree) _git_ls_tree ;;
1908 mergetool) _git_mergetool;;
1909 merge-base) _git_merge_base ;;
1911 name-rev) _git_name_rev ;;
1914 rebase) _git_rebase ;;
1915 remote) _git_remote ;;
1916 reset) _git_reset ;;
1917 revert) _git_revert ;;
1919 send-email) _git_send_email ;;
1920 shortlog) _git_shortlog ;;
1922 show-branch) _git_show_branch ;;
1923 stash) _git_stash ;;
1925 submodule) _git_submodule ;;
1928 whatchanged) _git_log ;;
1935 __git_has_doubledash && return
1937 local cur="${COMP_WORDS[COMP_CWORD]}"
1938 local g="$(__gitdir)"
1940 if [ -f $g/MERGE_HEAD ]; then
1946 $__git_log_common_options
1947 $__git_log_gitk_options
1953 __git_complete_revlist
1956 complete -o bashdefault -o default -o nospace -F _git git 2>/dev/null \
1957 || complete -o default -o nospace -F _git git
1958 complete -o bashdefault -o default -o nospace -F _gitk gitk 2>/dev/null \
1959 || complete -o default -o nospace -F _gitk gitk
1961 # The following are necessary only for Cygwin, and only are needed
1962 # when the user has tab-completed the executable name and consequently
1963 # included the '.exe' suffix.
1965 if [ Cygwin = "$(uname -o 2>/dev/null)" ]; then
1966 complete -o bashdefault -o default -o nospace -F _git git.exe 2>/dev/null \
1967 || complete -o default -o nospace -F _git git.exe