This answer teaches how to do custom bash commands inside git aliases, and this article (One weird trick for powerful Git aliases) teaches it beautifully. However, it doesn't seem to work when I alias internal git commands. How can I replace internal git commands with custom scripts?
Ex: I have a custom python script: custom_script.py
print("hello")
In my project_name/.git/config
file I add this alias:
[alias]
statuss = "!f() { \
python3 custom_script.py && git status; \
}; f"
I then run git statuss
and it works perfectly! I see "hello" printed out, followed by the "git status" return messages.
HOWEVER, if I rename my alias name from statuss
to status
, it no longer works.
[alias]
status = "!f() { \
python3 custom_script.py && git status; \
}; f"
How can I do this so that by simply calling git status
, it first calls my "custom_script.py" and then runs git status
?
Notes:
- Ideally, this would work in Windows, Mac, or Linux, but Linux is what I care about most, so a Linux-only solution would be ok.
- Ideally, I'd like to do this via a git alias, but if I need to use a bash alias or other Linux/computer trick, that's better than nothing.