krlmlr
krlmlr

Reputation: 25484

Show expanded version of Git command

Is there a way to have Git print the semantics of an aliased command before executing it?

Assuming I have aliased a to add, I'd like the command git a to show

Executing: git add

before the actual output. Or perhaps there's an echo subcommand so that I alias a to echo add and the subcommand prints and actually executes the command?

Upvotes: 2

Views: 84

Answers (2)

Philipp Wendler
Philipp Wendler

Reputation: 11423

If you don't mind that a little bit more is printed, you can set the GIT_TRACE variable to 1 and git will print (among other) some information about alias expansion (cf. the man page).

In my case (I have defined an alias st for status), this looks like this:

$ GIT_TRACE=1 git st
trace: exec: 'git-st'
trace: run_command: 'git-st'
trace: alias expansion: st => 'status'
trace: built-in: git 'status'

Of course, you can for example put export GIT_TRACE=1 in your .bashrc to have this always enabled.

If you really want to show only the alias expansion, you could probably define a shell alias for git that runs git and filters out all lines from the output that start with trace: but do not contain alias expansion:.

Upvotes: 2

Schleis
Schleis

Reputation: 43800

You will need to define the alias to include the echo statement for you.

One way would be to define the alias like this:

"!echo \"executing git add\"; git add" 

There are a few different ways to do it that you can find in this question:

How to embed bash script directly inside a git alias

Upvotes: 1

Related Questions