I'm having difficulty getting Git to cooperate with my user-defined worktree that exists outside the folder that contains my .git directory.
Basically the setup is like this: I have two directories, one called "git-worktree" which houses the file I want to track & another called "git-dir" which contains the repository's .git folder aka the GIT_DIR.
I init the repository by cd'ing into folder "git-dir" and running:
git --git-dir=./.git --work-tree=/Users/braitsch/Test/git-worktree/ init
This successfully initializes the repository and while I'm in the "git-dir" folder I can add files that are in the work-tree, run git status and commit them. Cool.
The kick comes when I try to run git stash
, which slaps me with the error:
fatal: /usr/local/git/libexec/git-core/git-stash cannot be used without a working tree.
Now this is nonsense, because I know (or at least I think) I have the work-tree set to the "git-worktree" folder that contains the files I want to track.
git config --local -l
shows me the following :
core.repositoryformatversion=0
core.filemode=true
core.bare=false
core.logallrefupdates=true
core.worktree=/Users/braitsch/Test/git-worktree
core.ignorecase=true
I even tried manually adding the .git folder to the local config file to see if that helps but to no avail.
core.gitdir=/Users/braitsch/Test/git-dir/.git
Now here comes the kicker. Git stash will work if I set the worktree to a directory that is a parent of the git-dir e.g. If I set the worktree to say my home directory.
core.worktree=/Users/braitsch/
So the question I have is what setting am I missing to tell Git to allow my worktree to exist anywhere on the filesystem, not just along a parent path of the git-dir back up to the root? Surely there must be a way to place your git-dir & your work-tree wherever you want and after telling Git where they are, and have everything work?
git --git-dir=<your path> --work-tree=<work tree path> stash
should work. Have you tried absolute paths?
UPDATE:
seems to be a bug. The extended functionality of --git-dir option was only added recently and some commands like git stash don't have the new implementation yet.
git-stash is a bash script. You could hack it and remove the require working dir check then cd into the working folder.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With