I found a peculiar behavior with git, and I can reproduce it every time on my machine.
If I have two local repositories, one bare inside the folder express.git
If you run git --git-dir=some/dir/.git pull
, by default git
will assume the current directory is the work tree. Not the parent of some/dir/.git
, but your current pwd
. This means that running that command will try to update the current directory as if it's the work tree and will end up writing files into your pwd
that don't belong there.
The appropriate solution is to use the --work-tree
flag in conjunction with --git-dir
to tell it where the work tree is. In this case you'd want git --git-dir=some/dir/.git --work-tree=some/dir pull
. However, after experimentation it seems there's a second problem here. If you try this command as-is, you'll probably be told git-pull cannot be used without a working tree
. It seems the issue here is git
needs its work tree to be an absolute path instead of a relative one.
What you really want to run is git --git-dir=some/dir/.git --work-tree="$PWD"/some/dir pull
. Alternatively, you could just try cd some/dir && git pull
. If you don't want to change your cwd, you can wrap this in a subshell, i.e. ( cd some/dir && git pull )
.