2

I copy pasted a git repository from windows to linux, from a shared directory, to a standard one. And now, any git command returns the error:

fatal: Invalid path '/shared': No such file or directory.

I tracked down the issue to a vestigial parameter from .git/config which defines:

[core]
    worktree = //shared/directory/source/project

Indeed, under linux, this dir does not exist nor is a valid path... I could solve the issue by deleting the incriminated line. But I couldn't find a single git command to reset this in a cleaner manner.

yota
  • 2,020
  • 22
  • 37
  • 1
    `git config` is the general-purpose command to tweak those files, but mostly editing them is fine too. – Joachim Sauer Sep 10 '20 at 09:21
  • 2
    Does [this](https://stackoverflow.com/questions/28522089/how-can-i-copy-my-git-repository-from-my-windows-machine-to-a-linux-machine-via) help? It's about exporting/importing a Git repo with `git bundle` :) – Tim Sep 10 '20 at 09:23
  • Why would there be a single dedicated command to fix up your worktree path? Just use `git config` to fix your config. – Useless Sep 10 '20 at 09:26
  • What the OP tries to achieve is impossible, the correct ways to export/import Git repositories across platforms are git clone or bundle. – Tim Sep 10 '20 at 09:32
  • @Useless why wouldn't git solve this issue automatically since this worktree seems to contains only the current directory ?! – yota Sep 10 '20 at 09:53

1 Answers1

3

The core.worktree setting is documented.

If you want to change it using a Git command, use git config core.worktree new-setting. If you want to delete it, use git config --unset or git config --unset-all.1 Of course, if it's currently set to an unusable path, you get an error:

$ git config core.worktree /no/such/path
$ git config --get core.worktree
fatal: Invalid path '/no': No such file or directory

It might be nice if git config caught this problem internally and just avoided the attempt to chdir to the core.worktree path, but there's an easy workaround:

$ git --work-tree=. config --unset core.worktree

so unless/until someone modifies Git to avoid the early fatal, use the workaround.


1The only reason to use --unset-all is if there is more than one core.worktree setting. Normally there would not be.

torek
  • 448,244
  • 59
  • 642
  • 775
  • Accepted ! This answer and the explanations make sense (the command is as unintuitive as every other git commands, but at least it is a command :D) – yota Sep 15 '20 at 15:24