Reputation: 589
I have an aliases.sh file modified with
alias gc='git checkout'
and upon checking out a long branch name, if I type
gc <branchstring>
+ TAB , auto-complete doesn't work, in order for the full branch name to appear.
Upvotes: 7
Views: 3189
Reputation: 589
I looked through everything in this thread to try to make it work for & tailor what kpsfoo said, but for the Windows 10 OS.
The steps would be to:
1) Copy the git-completion.bash file from
<your git install folder>/etc/git-completion.bash
to
C:\Users\<YourUserName>\git-completion.bash
2) add this line of code:
source ~/git-completion.bash
to your aliases.sh file
(which can be found in <your git install folder>\etc\profile.d
)
3) Add alias gc='git checkout'
&
Add __git_complete gco _git_checkout
anywhere after the source ~/git-completion.bash
line in your aliases.sh file.
4) Reboot your git bash and enjoy your alias auto completion!
Example:
If I have a branch VeryVeryLongBranchName
and I'm currently on dev
branch, and want to switch to it, instead of typing
git checkout VeryVeryLongBranchName
I can type only
gc Very
+TAB key and it is the equivalent of the instruction above.
alias ga="git add"
alias gb='git branch'
alias gba="git branch -a"
alias gc='git checkout'
alias gcb='git checkout -b'
alias gcam='git commit -a -m'
alias gm='git merge --no-ff'
alias gps='git push wpdev dev'
alias gpsm='git push wpdev master'
alias gpl='git pull wpdev dev'
alias gplm='git pull wpdev master'
alias st='git status'
alias l='git log --graph --pretty='\''%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset'\'' --abbrev-commit'
alias last='log -1 HEAD'
alias gs='git stash'
# Enable the __git_complete function to autocomplete aliases once you press TAB
source ~/git-completion.bash
__git_complete ga _git_add
__git_complete gc _git_checkout
__git_complete gm _git_merge
__git_complete gb _git_branch
__git_complete gba _git_branch
__git_complete l _git_log
case "$TERM" in
xterm*)
# The following programs are known to require a Win32 Console
# for interactive usage, therefore let's launch them through winpty
# when run inside `mintty`.
for name in node ipython php php5 psql python2.7
do
case "$(type -p "$name".exe 2>/dev/null)" in
''|/usr/bin/*) continue;;
esac
alias $name="winpty $name.exe"
done
;;
esac
-worth of note: alias gm='git merge --no-ff'
goes just fine with __git_complete gm _git_merge
(when typing gm plus a string from your branch name and pressing TAB, it will autocomplete, and, after you run the command, the merge will take into consideration the --no-ff rule)
Upvotes: 8