-4

In folder D:\projects\A I have the .git folder for A. Is there a way to move it to D:\gitfolder\A? I found these similar questions:

So far I've moved the .git folder already. In D:\gitfolder\A git status works fine, but I'm not sure if it can add new files created in D:\projects\A or not.

If possible I would like to be able to still use git commands in D:\projects\A as if the move didn't happen.

Ooker
  • 1,969
  • 4
  • 28
  • 58

1 Answers1

-1

In folder D:\projects\A create a file (not folder) named .git with this content:

gitdir: D:\gitfolder\A\.git

In folder D:\gitfolder\A\.git edit the config file with this line under [core]:

worktree = D:\projects\A

You can also do this with this command git config core.worktree D:\projects\A.

Note that if your path containing space (e.g. D:\multiple words\A), then the texts in the .git or config files should have double slashes (i.e. D:\\multiple words\\A). And if you use the command, the path should be in quotes git config core.worktree "D:\multiple words\A".

Ooker
  • 1,969
  • 4
  • 28
  • 58
  • 1
    The backslashes get interpolated in `.git/config` files (`core.worktree` setting) so that is where you need to double them; this isn't related to the spaces, which need quoting when present in a command line. (I'd be slightly, but not totally, surprised to find that they need doubling in the `.git` file with the `gitdir` line too.) To avoid the double-backslash-problem you can simply use forward slashes, which work fine on Windows and have the benefit of being easier to type, as well as no issues with doubling. – torek Jun 11 '22 at 13:58