简体   繁体   中英

How do I add autocomplete to git aliases?

I have setup git autocomplete using the git-autocomplete.bash file which works for standard commands and simple aliases ( co = checkout ), but I have a longer alias defined in my .git-config file that I would like to autocomplete branch names on and I cannot find how to do this.

I am on Windows Server 2012 R2 running git 2.10.2.windows.1

My alias looks like this:

mstage = "!git checkout stage && git pull && git reset --hard && git merge $1 --no-commit"

where $1 is a branch name - I'd love this to autocomplete

here we have two options for windows operating system:

msysgit

  1. Download and place git-flow-completion.bash in home directory ( ~/ in msysgit shell)
  2. Add a .bashrc file to your home directory with the following line (or add this line to existing .bashrc file):

    source ~/git-flow-completion.bash

Cygwin

  1. Download and place git-flow-completion.bash in

    %CYGWIN_INSTALLATION_DIR%\\etc\\bash_completion.d

  2. Rename it to git-flow

    you can autocomplete as following: git flow init etc.

@Rohit Poudels answer works if you are using bash on Windows. If you are using PowerShell, currently the only way to enable this autocomplete is to change posh-git manually after installing.

I changed the GitTabExpansion.ps1 file in posh-git, similarly to what is outlined on the repo .

More specifically, I added $line = $line -replace '^git mstage ', 'git checkout ' as the first line in the function TabExpansion which will in effect will treat my alias as equivalent to git checkout and tab expansion will then behave as expected

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM