Git在命令上使用--work-tree和--git-dir

So, I have a php script that integrates with BitBucket's API and make changes to some local/shared repositories.

To do that, I use --git-dir and --work-tree [when applicable] together with every command, as in:

/usr/bin/git --git-dir=/var/www/staging.repo/.git --work-tree=/var/www/staging.repo merge "origin/master" 2>&1; echo $?

I use git version 1.7.0.4 on my development environment, and git version 1.5.6.5 on the live server. The reason for it is that there's no newer version of git for Debian Lenny (5), so I'm stuck with the older one.

The problem is, some of the commands that correctly accept --work-tree and --git-dir on git v1.7 doesn't seem to care much about it on the older version. One example is:

/usr/bin/git --git-dir=/var/www/staging.repo/.git --work-tree=/var/www/staging.repo merge "origin/master" 2>&1; echo $?

That outputs:

fatal: /usr/bin/git-merge cannot be used without a working tree.

So, how can I make broad use of those parameters using git 1.5.6.5?


Solution:

Downloaded git source:

myself:/some/folder$ curl -O http://git-core.googlecode.com/files/git-1.7.7.tar.gz

Installed:

myself:/some/folder/git-1.7.7.tar.gz$ ./configure

myself:/some/folder/git-1.7.7.tar.gz$ make

myself:/some/folder/git-1.7.7.tar.gz$ sudo make install

Done! :)

Ref: http://www.mikepilat.com/blog/2011/06/how-to-build-git-from-source-on-ubuntu/

Please compile the latest git.

Yes, some commands don't observe those parameters. You can try and set their equivalent environment variables instead.