noisy noisy - 1 year ago 115
Git Question

Is it possible to override git command by git alias?

my ~/.gitconfig is:

commit = "!sh"

However, when I type git commit, script is not called.

Is it possible, or I have to use another alias name?

Answer Source


This is from my clone of git.git:

static int run_argv(int *argcp, const char ***argv)
    int done_alias = 0;

    while (1) {
        /* See if it's an internal command */
        handle_internal_command(*argcp, *argv);

        /* .. then try the external ones */

        /* It could be an alias -- this works around the insanity
         * of overriding "git log" with "git show" by having
         * alias.log = show
        if (done_alias || !handle_alias(argcp, argv))
        done_alias = 1;

    return done_alias;

So its not possible. (handle_internal_command calls exit if it finds the command).

You could fix this in your sources by changing the order of the lines and making handle_alias call exit if it finds the alias.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download