Create a git alias to show files marked as --assume-unchanged?

273 views Asked by At

I'm trying to follow the instructions in this answer, to create an alias for a wordy git command:

Edit your .gitconfig file to add this snippet:

[alias]
    ignored = !git ls-files -v | grep "^[[:lower:]]"

I have two questions:

  1. Where can I find .gitconfig on Mac OS X?
  2. How can I do this from the command line?

Following the simple instructions here, I have tried...

git config --global alias.ignored "ls-files -v | grep '^[[:lower:]]'"

and

git config --global alias.ignored "!git ls-files -v | grep '^[[:lower:]]'"

The first command is successful, but then git ignored produces no output. The second tells me I'm doing it wrong.


Edit: here is what happens when I run this second command:

$ git config --global alias.ignored "!git ls-files -v | grep '^[[:lower:]]'"
git config --global alias.ignored "git push -u origin --all ls-files -v | grep '^[[:lower:]]'"
$ git ignored
Expansion of alias 'ignored' failed; 'git' is not a git command

After this command, the .gitconfig file contains...

[alias]
    ignored = git push -u origin --all ls-files -v | grep '^[[:lower:]]'

... which does not look like he command that I thought I was setting.

1

There are 1 answers

1
Kristján On BEST ANSWER

As @maggick said in the comments, .gitconfig goes in your home directory.

Your second command is failing because your shell interprets "!git" as a history search. For example:

$ echo 'hi'
hi
$ cat < /dev/null
$ !echo
echo 'hi'
hi

Your attempt without !git avoids that issue, but you can't pipe to further commands unless you tell Git the alias is a full shell command (vs a direct to Git command) with the bang.

The shell interpolates into double quotes, but not single quotes, so invert the quotes in your alias command, or escape the inner single quotes:

$ git config --global alias.test '!git ls-files -v | grep "foo"'