Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
241 views
in Technique[技术] by (71.8m points)

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.

Question&Answers:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...