Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Any reason to use a Git alias instead of a git-* script?

Tags:

git

alias

In Git, you can create custom commands using either an alias or by creating an executable file, included in your PATH, starting with git-. Is there any reason to choose an alias as opposed to a script?

I work with a team of developers and have made some handy aliases I'd like to share with them. A colleague of mine suggested that aliases should be used for simple things, like shortening a command (e.g. git co as an alias for git checkout), and that scripts would be useful for more complicated tasks, like combining multiple functions into one. But he couldn't come up with any reason why not to use scripts, not sure if it's just how he felt it should be, or if he had heard somewhere that that's how it should be, or what.

Our team all works on the same development server, so if I can use a script, I can simply put it in /usr/local/bin and everyone will have access to it automatically. So even with a simple alias, it would be much more convenient to just have it as a git script so that everyone automatically has it, as opposed to me having to tell everyone to set it up individually. Not to mention, when a new developer starts, we would have to remember to have them set it up as well.

I know it sounds like I'm campaigning for the script approach, and I am. I'm just wondering if there is any drawback to using that approach.

like image 467
Travesty3 Avatar asked Feb 12 '15 13:02

Travesty3


People also ask

What is git alias?

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.

Where do I put git alias?

Your git aliases are often stored per your user's configuration at ~/. gitconfig . You can also manually set aliases using, for example, the command git config alias. s 'status -s' .

How can add a git URL as an 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

With using git aliases you will be able to use autocompletion of branch names, tags, etc

like image 153
phts Avatar answered Sep 16 '22 18:09

phts