问题
I'm running (in a script - trying to avoid using cd):
git --git-dir=/test/.git --work-tree=/test/ pull
And getting:
fatal: /usr/lib/git-core/git-pull cannot be used without a working tree.
Note that I've run other commands with exactly this structure that have worked (in particular, add, commit, and pull), so I think it's just a pull problem.
A similar problem is documented here: Git pull fails to parse syntax, but it's not quite the same - they get a different error (and they're running on Windows, so who knows... I'm on Ubuntu).
回答1:
Thanks to isbadawi for this answer.
Turns out this question has been answered before: git pull while not in a git directory.
In a nutshell, this is a bug with git pull. However, since pull is basically an alias for fetching and merging, the following is equivalent to pull (copied from the above link):
cd /X
git --git-dir=/X/Y/.git fetch
git --git-dir=/X/Y/.git --work-tree=/X/Y merge origin/master
来源:https://stackoverflow.com/questions/15080877/git-pull-with-work-tree-flag-fails