Let say I have an alias like this in my .gitconfig:
alias.showlog = log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset'
and now I want a similar alias like this:
alias.sl = showlog --abbrev-commit
When I try the command git sl
it say he does not know the showlog
command.
I know it is still possible to copy the same command like the other alias, but I just want to know if there is any possibility to refer another alias in 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 .
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.
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' .
Use git la to show aliases in . and simply defined another alias to grep the TAB = part of the defined aliases.
Update Q4 2018: Yes, it is possible possible with Git 2.20: an alias that expands to another alias has so far been forbidden, but now it is allowed to create such an alias.
See commit fef5f7f, commit 82f71d9, commit c6d75bc (16 Sep 2018) by Tim Schumacher (timschumi
).
(Merged by Junio C Hamano -- gitster
-- in commit 506ee60, 16 Oct 2018)
alias
: add support for aliases of an alias
Aliases can only contain non-alias git commands and their arguments, not other user-defined aliases. Resolving further (nested) aliases is prevented by breaking the loop after the first alias was processed.
Git then fails with a command-not-found error.
Allow resolving nested aliases by not breaking the loop in
run_argv()
after the first alias was processed.
Instead, continue the loop untilhandle_alias()
fails, which means that there are no further aliases that can be processed. Prevent looping aliases by storing substituted commands incmd_list
and checking if a command has been substituted previously.
So... this will be possible now:
git config alias.nested-internal-1 nested-internal-2
git config alias.nested-internal-2 status
git nested-internal-1
That would be a git status
.
With Git 2.30 (Q1 2021), the command line completion script (in contrib/) learned to expand commands that are alias of alias.
See commit e4c75ed (12 Nov 2020), and commit c2822a8, commit 9414938 (09 Nov 2020) by Felipe Contreras (felipec
).
(Merged by Junio C Hamano -- gitster
-- in commit fd6445a, 25 Nov 2020)
completion
: bash: support recursive aliasesSigned-off-by: Felipe Contreras
It is possible to have recursive aliases like:
l = log --oneline lg = l --graph
So the completion should detect such aliases as well.
In versions of Git before 2.20:
Not that way, but you can make an alias run a command through the shell, hence running another instance of git
which resolves the second alias:
alias.sl = !git showlog --abbrev-commit
In 2.20 or later, see VonC's answer.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With