If I do this:
alias g='git'
I loose all completion rules (i.e. branches and remotes are no longer being automatically completed when I hit TAB after typing, for example g push o
).
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It only takes a minute to sign up.
Sign up to join this communityLatest bash-completion upstream moved and renamed things a bit. It's now:
source /usr/share/bash-completion/completions/git
__git_complete g __git_main
Use this in recent versions of Ubuntu (e.g. 14.04, also Fedora 22+) when you encounter:
completion: function `_git' not found
during completing.
__git_complete gc _git_checkout
(or similar) to set up completions for more specific aliases. Search /usr/.../git
as above to find the right name.
Nov 6, 2015 at 18:00
gc
=> git checkout
) as opposed to aliasing c
to checkout
within git
, and saying git c
. Correct me if I'm wrong.
Oct 24, 2016 at 12:33
Copying and modifying opportunely from /etc/bash_completion.d/git
, add the following lines to your ~/.bashrc
:
complete -o bashdefault -o default -o nospace -F _git g 2>/dev/null \
|| complete -o default -o nospace -F _git g
source /usr/share/bash-completion/completions/git
to my .bashrc
.bashrc
code here works, but this answer is definitely out of date. /etc/bash_completion.d/git
doesn't seem to exist on 14.04. See lzap's answer below.
Nov 6, 2015 at 18:04
In ~/.bashrc
:
alias g='git'
source /usr/share/bash-completion/completions/git
complete -o default -o nospace -F _git g
Via http://29a.ch/2013/8/9/fixing-bash-autocomplete-on-ubuntu-13-04
alias g='git'
, but I use Izap's answer to this question for the bash completion.
Nov 14, 2022 at 20:54
First, look up the original completion command. Example:
$ complete | grep git
complete -o bashdefault -o default -o nospace -F __git_wrap__git_main git
Now add these to your startup script (e.g. ~/.bashrc):
# copy the original statement, but replace the last command (git) with your alias (g)
complete -o bashdefault -o default -o nospace -F __git_wrap__git_main g
# load dynamically loaded completion functions (may not be required)
_completion_loader git
The _completion_loader
line may not be required. But for some situations, the completion function is only loaded dynamically after you type the command and press TAB
the first time. So if you haven't used the original command, and try the alias + TAB
, you may get an error like "bash: completion: function not found".
The updated way to do this (complete wouldn't work for me):
cd
- switch to your home directorywget https://raw.github.com/git/git/master/contrib/completion/git-completion.bash
source ~/git-completion.bash
to your .bashrc file (if you don't have this file make one in your home folder, bash will look for it automatically)alias g='git'
to your .bashrc file.source ~/.bashrc
__git_complete g _git
Nov 3, 2015 at 6:08
Just for the sake of completeness, I'd like to add an answer using the ~/.bash-completion
file, which gets sourced at the end of the bash-completion script:
_xfunc git __git_complete g __git_main
_xfunc git __git_complete gl _git_log
_xfunc git __git_complete gd _git_diff
_xfunc git __git_complete gb _git_branch
Then in my ~/.bashrc
I have just the aliases. I was trying to:
~/.bashrc
with bash-completion stuff (keep stuff where it belongs) ✓Unforutnately the _xfunc
sources the git-completion anyway. I'll update this answer once I figure out how to do it properly (I also asked on lunchpad here).
Look at here: https://gist.github.com/scue/576310b7c6b7714aad05
wget https://gist.github.com/scue/576310b7c6b7714aad05/raw/459d46761c231f5c373c1cf496920b01bb6669d2/.bash_aliases.git -O ~/.bash_aliases.git
echo "test -e ~/.bash_aliases.git && source ~/.bash_aliases.git" >> ~/.bashrc
Enjoy!(^o^)/
You may just define aliases as usual:
alias g='git'
Then install complete-alias to make bash completion alias-aware.
g=git
756 times in the past month, meaning I saved pressing the 'g' and 'i' keys 1512 times total. That, combined with my git aliases, probably saves me tens of thousands of key presses a month.