Summary: the current working directory of commands run through git aliases is wrong.
The easiest way to demonstrate this is to have a git alias like so:
[alias]
pwd = !pwd
So git pwd
is just running the bash command pwd
. One would think that the two commands' outputs would be the same. Now, let's try this out a few times:
$ cd ~
$ pwd && git pwd
/home/limpchimp
/home/limpchimp # great!
$ mkdir foo && cd foo && git init
Initialized empty Git repository in /home/limpchimp/foo/.git/
$ pwd && git pwd
/home/limpchimp/foo
/home/limpchimp/foo # great!
$ mkdir bar && cd bar
$ pwd && git pwd
/home/limpchimp/foo/bar
/home/limpchimp/foo # uuhhhhhhhh...?
It seems that git is changing the current working directory to be the first parent directory that has a .git
folder (if one exists). This is very problematic; it's screwing up certain scripts that I've written, which are meant to operate in a specific directory, and making me unable to use certain things as git aliases. Is there a way around this? How can I fix it?