Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Alias "git git" to just "git"?

Tags:

git

Every now and then I wind up typing "git" then think of something else, then type e.g., "git checkout master". Of course, this leaves me with

$ git git checkout master
git: 'git' is not a git command. See 'git --help'.

Did you mean this?
    init
$

Is there a way to create a git alias named git that is a no-op? I've tried the obvious like "git = ''" and "git = """ and "git = " "" but not surprisingly, they all result in responses like Expansion of alias 'git' failed; '' is not a git command.

like image 243
Ben Avatar asked Oct 07 '14 11:10

Ben


People also ask

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' .

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.

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

I figured out the answer: Rather than alias, you just need to have script named git-git in your path with the contents:

#!/bin/bash
git "$@"

so when you say "git git", git looks for git-git, and passes the remaining arguments to it. Of course, by recursion, you can be very absent minded and say "git" as many times as you like:

$ git git git git git git git git git git git git status # <- still works

Update: Yesterday I hit enter on gitgit status. So, while you are at it, may as well symlink git-git to gitgit. That doesn't chain indefinitely, but still.

like image 87
Ben Avatar answered Sep 28 '22 14:09

Ben