Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to override git command by git alias?

Tags:

git

alias

my ~/.gitconfig is:

[alias]         commit = "!sh commit.sh" 

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

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

like image 688
noisy Avatar asked Aug 21 '10 20:08

noisy


People also ask

What is the use of alias in git?

Git aliases are a powerful workflow tool that create shortcuts to frequently used Git commands. Using Git aliases will make you a faster and more efficient developer. Aliases can be used to wrap a sequence of Git commands into new faux Git command.

How do I edit a git alias?

Start a new branch. gitconfig file and add each alias under [alias], like so: Additionally, you can have repo-specific aliases. Just edit . git/config in the repo where you want to add the alias, and follow the same syntax.

How can add a git URL as an alias?

Add git alias The simplest way to add a git alias is by running a command to add the alias to the git global configuration file. For example, running the command git config --global alias. hist "log --pretty=format:'%h %ad | %s%d [%an]' --graph --date=short" will add the alias git hist .


1 Answers

It is NOT POSSIBLE

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 */         execv_dashed_external(*argv);          /* 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))             break;         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.

like image 161
alternative Avatar answered Oct 31 '22 21:10

alternative