vretamal
vretamal

Reputation: 1515

How to use bash commands on .gitconfig aliases

I use the command git ls-tree -r $(git branch | awk '{ print $2 }') --name-only to show the files on my branch, but i tried to put this command on my .gitconfig file as an alias and i got this error:

  $ git list
fatal: Not a valid object name $(git

My .gitconfig file:

[alias]
list = ls-tree -r $(git branch | awk '{ print $2 }') --name-only

Thanks P.D. Sorry for my english

Upvotes: 3

Views: 1159

Answers (1)

Anshul Goyal
Anshul Goyal

Reputation: 77053

As already pointed out in comments, you need to prefix your alias with an exclamation (!) mark.

The following entry works for me

[alias]
    list = !git ls-tree -r $(git branch | awk '{ print $2 }') --name-only

EDIT

Alternatively, taking help from this answer, you can create a file git-list in any place in your PATH, like below:

git-list

git ls-tree -r $(git branch | awk '{ print $2 }') --name-only

then change its permission to executable using chmod +x git-list and you can have your git list command working in any directory.

Upvotes: 3

Related Questions