For an alias to git itself, eg. alias g=git, you'll find your answer more easily here.
For git subcommand aliases, eg. alias gco = "git checkout", look here.
I type git far too often, so I've aliased it:
alias g='git'
However, now I can't do:
g comtab
and have the completion present me with:
g commit
How do I get completion running again?
Duplicate differentiation
This equal-first meta answer suggests keeping the specific case with a with a link to the more generic question. I've added the link to the more generic case in this edit.
The asserted duplicate question is more generic - but mostly about aliases to git subcommands, rather than an alias to git itself.
This question is about the specific case where the alias is to git itself.
In the marked duplicate, the git-itself case is only answered in the 4th shown answer, and in a comment to the first listed answer. Reading another comment is required for the second piece of the puzzle (source /usr/share/bash-completion/completions/git) to get it working via that method.
Addressing the links in the comments below:
git subcommandsgit aliases, which doesn't isn't near to the best solution in this caseAt the end of your .bashrc, add:
_xfunc git __git_complete g _git
If you see bash: _xfunc: command not found, use the longer form:
source /usr/share/bash-completion/completions/git
__git_complete g _git
Reload bash
exec bash
(This answer was inspired by the kub1x's answer and the comments in a question about completion of git subcommand aliases)
Add the following in your .bashrc file:
source /usr/share/bash-completion/completions/git
complete -o default -o nospace -F _git g
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With