user1445967
user1445967

Reputation: 1570

Git "repository separate from work tree" solution not working under Windows

See the answer that I linked to this question:

https://stackoverflow.com/a/8603156/1445967

I could not get this to work at all under the latest Git for windows. (Windows 7 x64)

I used git bash:

<my username> /d/<worktree>
$ git --git-dir=/c/dev/gitrepo/repo.git --work-tree=. init && echo "gitdir: /c/dev/gitrepo/repo.git" > .git
Initialized empty Git repository in c:/dev/gitrepo/repo.git/

Then I tried:

<my username> /d/<worktree>
$ git status
fatal: Not a git repository: /c/dev/gitrepo/repo.git

So I tried something slightly different, thanks to the way windows paths get stored...

<my username> /d/<worktree>
$ git --git-dir=/c/dev/gitrepo/repo.git --work-tree=/d/<worktree> init && echo "gitdir: /c/dev/gitrepo/repo.git" > .git
Initialized empty Git repository in c:/dev/gitrepo/repo.git/

This is copy-paste verbatim except I changed my username and a single directory name to <worktree> for SO.

Then I tried the following:

<my username> /d/<worktree>
$ git status
fatal: Not a git repository: /c/dev/gitrepo/repo.git

Then I looked inside /c/dev/gitrepo/repo.git/config and I saw this:

worktree = d:/<worktree>

Maybe this won't work with the windows path notation. So I changed it:

worktree = /d/<worktree>

Still no luck. Is what I am trying to do possible under git for Windows?

Upvotes: 1

Views: 519

Answers (1)

user1445967
user1445967

Reputation: 1570

The only progress I have made on this question is the discovery that on the workstation I was using, the SUBST command was used to create drive D. That is to say, C and D are really the same physical drive.

SUBST does not seem to completely break Git though. I have the project on drive D and the git repo on a completely different directory on drive D and everything works.

username@host /d/ProjectName (branch)
$ cat .git
gitdir: d:\gitrepo\ProjectName.git

So the best answer I have is a workaround, where I advise: In Windows there may be an issue:

1.  If the repo and working dir are on different drives
2.  If (1) is true and you use SUBST

But whichever of those is the case, the work around is one or both of the following:

1.  put everything on the same drive letter.  It works even if that drive is a 'subst' drive.
2.  Use the windows "d:\" notation in the .git file

Upvotes: 1

Related Questions