'git ls-files run from subdirectory

I'm trying to make a shell.sh that when run with bash will basically just run command: git ls-files -o -i --exclude-standard

which works perfectly when run from base repo directory, but when i change current directory to *repo/folder and run it from there, there is no output.

so: \
 *repo/git ls-files -o -i --exclude-standard -- good \
 *repo/folder/git ls-files -o -i --exclude-standard -- no bueno

does anyone know why it does this and how to remediate? Thanks



Solution 1:[1]

Running git ls-files is a little like running ls -R -- it only considers files in the current directory or below. It's producing no output because (presumably) the only files matching your criteria existing only at the top level of the repository.

It sounds like you always want to run git ls-files from the top directory, regardless of your current location. You can do that like this:

git -C $(git rev-parse --show-toplevel) ls-files -o -i --exclude-standard

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 larsks