Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
# This adds tab completion of git branch names (including remotes) to several
# git-related bash aliases I have set up:
#
# co git checkout
# gb git branch
# gm git merge
#
#
# Bugs:
#
# When I tab-complete the empty string I get a directory listing plus the
# remotes. I would prefer to just have all branches.
#
#
# References:
#
# https://raw.github.com/django/django/master/extras/django_bash_completion
# http://fahdshariff.blogspot.com/2011/04/writing-your-own-bash-completion.html
_branch_names()
{
local cur=${COMP_WORDS[COMP_CWORD]}
COMPREPLY=( $(compgen -W "`gb` `gb -r`" -- $cur) )
}
complete -F _branch_names co
complete -F _branch_names gb
complete -F _branch_names gm
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.