InviS InviS - 3 years ago 193
Git Question

Git change working directory

I want to work with Git repository, but working tree should be remote. For example: if I have my project stored inside of

stored inside of

What I've changed working tree via config:


And I'm able to commit and view diff, but when I've tried to do
git stash
, I got error:

fatal: /usr/libexec/git-core/git-stash cannot be used without a working tree.

How to store
directory far from working tree?
And why I'm getting this error?

git config --get core.worktree
returns correct working directory....

Answer Source

The following seems to work, adjust to your needs:

mkdir git
mkdir work
git --git-dir git/test --work-tree work/test init
mkdir work/test
echo -n foo > work/test/foo.txt
git --git-dir git/test status
git --git-dir git/test add foo.txt
git --git-dir git/test commit -m 'commit 1'

EDIT: Notice that you don't have to specify --work-tree after the repo has been initialized since that value is stored in git/test/config.

You can also cd into work/test and commit from there:

cd work/test
echo -n bar > bar.txt
git --git-dir ../../git/test status
git --git-dir ../../git/test add .
git --git-dir ../../git/test commit -m 'commit 2'

Then use an absolute path for --git-dir or set GIT_DIR.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download