Bash git alias tab completion error Bash git alias tab completion error bash bash

Bash git alias tab completion error


I'm guessing there's a custom completion function set up for git, and the error is in that setup. Try removing the custom completion first and see if the error disappears:

complete -r git

Side note: for shell commands with reusable arguments in a git alias, the modern idiom is to define a shell function, which lets you use standard shell argument processing and has one fewer levels of argument quoting to deal with when compared to 'sh -c':

[alias]  plush = "!f() { git pull \"$@\" && git push \"$@\" }; f"


I had the exact same problem. For example, I had an alias for deleting a local branch and its remote counterpart in one go:

[alias]db = "!f() { git branch -d $1 && git push origin :$1; }; f"

In order to fix the problem, I removed the alias and added a file named git-db to my Git scripts directory. It can be any directory in the PATH. Here's the contents of the file.

#!/bin/shgit branch -d $1 && git push origin :$1

Note that the file must not have an extension. It can be used just like the alias:

git db mybranch


This error is due to a shortcoming in the bash completion script that shipped with older versions of Git. It was not designed to handle shell aliases, which caused this error. This was fixed in commit 56f24e80f0, but this change was not included until Git 2.1.0. However, msysGit is as of this writing still on Git 1.9.5 and thus does not include the fix.

The preferred solution is to switch to Git for Windows, the successor to msysGit, which tracks current Git releases.

However, if you are stuck with an old version of Git, you can still work around the problem by replacing the alias with a custom script, as described in the answer by @Reinhard Nägele.