mediatribe.net -- Drupal et développement web

Notice: this post was last updated Il y a 3 years 40 weeks so it might be outdated. Please be cautious before implementing any of suggestions herein.

Git: specifying a directory without being in it

In case you don't want to cd into a directory, you can still target it with git. See also http://stackoverflow.com/questions/1386291. Here is an example:

mkdir test
cd test
git init
Initialized empty Git repository in /path/to/test/.git/
touch test.txt
git add .
git commit -am 'initial'
[master (root-commit) d0505e5] initial
0 files changed
create mode 100644 test.txt
cd ..
pwd
/path/to
git --git-dir=/path/to/test/.git --work-tree=/path/to/test log

Interestingly, it works in

Interestingly, it works in the above example, but when I'm trying to log onto a remote machine and try it with git pull, I get

fatal: /usr/libexec/git-core/git-pull cannot be used without a working tree.

To avoid that error I must do:

cd /my/git/repo && git pull origin master