I have a git repository with a few files and subdirectories. If I have a terminal window open in one of these subdirectories and execute git ls-files, I get a list of the files within my current working directory. If I create the following alias and run it in the same directory:
[alias] lsAlias = "!f () { params=($GIT_PREFIX); cd \"${params[0]}\"; /home/user/some-script.sh; }; f" some-script.sh calls pwd and git ls-files. pwd Correctly reports the current directory as expected, but git ls-files is behaving as if I am calling the command from the root of the git repository. If I adjust the alias to cut out the shell script:
[alias] lsAlias = "!f () { params=($GIT_PREFIX); cd \"${params[0]}\"; pwd; git ls-files; }; f" I get the same behavior.
Here is the transcript of the second alias:
+ f + params=($GIT_PREFIX) + cd TestApp/Training/ + pwd + git ls-files This is running in git-bash on Windows 10.
How do I have git ls-files respect the current working directory?
set -x;at the front of the alias to log execution, and add the transcript to the question.params=($GIT_PREFIX)has a lot of undefined behavior in it, so I'd typically suggest avoiding it. See BashPitfalls #50 -- and it only has the behavior described there if it's actually executed with bash. git aliases use/bin/sh, not bash, not bash, so array support isn't there at all./bin/shis provided by bash -- somewhere it was dash or ash you'd have a more explicit error from that code.declare -p "${!GIT_@}" >&2to list the environment variables named starting withGIT_set during the alias's execution. One of the results listed there will be responsible for the difference in behavior, so you can reverse that behavior change with an appropriateunset.ls-filesoutput local to the cwd, not the repository root.