git –git-dir not working as expected

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.

4 Answers
4

Leave a Comment