When answering "Git pull hook script which executes locally", I stumbled upon the use-case to alias a built-in git command such as pull
or push
with an extension. How do I do that?
First thought was:
[alias]
push = "!echo -n \"really push? [y/n]\";read -s -n 1 really;if [[ $really == \"y\" ]];then git push; else echo \"aborting\"; fi"
This works fine as long as I don't name my alias push
(for example qp
or something like that). But as soon as I call it push
, it's somehow ignored.
Is there a git way to expand a built in git command with an alias or do I have to set up an alias in my .bashrc
?
Short answer: you can't.
Git disallows this explicitly to prevent confusion and shadowing that might affect the invocation of git commands (in scripts, etc.). See the git-config manpage.
You could, as you noted, just name your alias something else and use that instead, or do it in
bash
. However, note that multiword aliases in bash are not possible, so you can't have an alias for "git push". Instead you'll need to use a function -- see "Bash: Spaces in alias name" on SuperUser for some hints (you can probably adopt it wholesale).