When creating a Git alias that points to a function, sometimes Git provides the wrong tab completion by default (e.g. filename completion instead of branch name completion). This is how we can tell Git, which type of completion to use.
Git Alias to a Function
Here is an example Git alias to a function that we could add to our .gitconfig
[alias]
echo = "!f() { \
echo $1; \
}; f"
by default hitting tab for completion options after git echo
will give us a list of filenames
e.g.
$ git echo
CHANGELOG.md LICENSE README.md
but if we want a list of branches instead we can tell Git to use the same completion used for git branch
(i.e. branch names) by adding the line
: git branch ; \
so we get
[alias]
echo = "!f() { \
: git branch ; \
echo $1; \
}; f"
Now our completion is branch names (and tags)
$ git echo
1.0.0 develop
1.1.0 main
FETCH_HEAD origin/develop
HEAD origin/main
ORIG_HEAD
Leave a Reply