hIpPy hIpPy - 4 years ago 97
Git Question

Is there a way to create a shortcut or alias for git option(s)

I find myself using

--name-status
option a lot with
git log
,
git diff
,
git show
. I'm aware of git aliases but they only work for a command or a combination of command and/or option(s). I do not want to create git aliases just for this option.

# l is an alias for log with pretty format
git l --name-status


So I can do something like this where
--ns
is shortcut for
--name-status
:

git l --ns





Update: See my own answer for the different considerations.

Answer Source

Barring modifying the source code to recognize additional flags, your best bet is probably using aliases to rewrite the flag:

[alias]
    l = "!l() { : git log ; git log $(echo \"$@\" | sed \"s/--ns/--name-status/\") ; } && l"

Alternatively you can define some alias g in bash that will do this for you (you can configure auto-complete to work with this but I don't remember how to do that off the top of my head):

function g {
    git $(echo "$@" | sed "s/--ns/--name-status/")
}
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download