tags:

views:

823

answers:

2

Hi all

I am trying to run git from a different directory than I am in. So for example if I am in:

cd /home/domain/
git status << runs perfect ie
# On branch master
# Your branch is ahead of 'origin/master' by 6 commits.

So now I want to run this command from a different directory using the --git-dir option.

So lets say I'm in root/ and try this:

git --git-dir="/home/domain/" status
## Error 
fatal: Not a git repository: '/home/domain/'

I've also tried to include the .git folder i.e.

git --git-dir="/home/domain/.git/" status

But this looks like it's trying to run git from the root, i.e. deleting everything from my domain folder and adding everything in root.

Hope someone can advise on what I'm doing wrong.

Thank you in advance if you can advise.

+7  A: 

You have to define the working dir as well. Confusing I know but it's a flexibility thing.

git --git-dir=/mycode/.git --work-tree=/mycode status

You can read a little more here

Jon Gretar
Thank You Jon. worked a charm.
Lee
+3  A: 
Greg Hewgill
Hi GregThat's fantastic. I never done that before and works a treat.
Lee