3

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

Anshul Goyal
  • 73,278
  • 37
  • 149
  • 186
vretamal
  • 1,485
  • 1
  • 10
  • 14
  • 1
    "If the alias expansion is prefixed with an exclamation point, it will be treated as a shell command". – Andrew C Nov 08 '14 at 01:38
  • 1
    possible duplicate of [How to embed bash script directly inside a git alias](http://stackoverflow.com/questions/1309430/how-to-embed-bash-script-directly-inside-a-git-alias) – Andrew C Nov 08 '14 at 02:16

1 Answers1

3

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.

Community
  • 1
  • 1
Anshul Goyal
  • 73,278
  • 37
  • 149
  • 186