Reputation: 45
I wish to clone a git repository owned by another (trusted) user on a shared system. Simply trying to clone it without any change to the git configuration does not work because recent versions of git introduced a safety check that blocks searching git repositories owned by other users:
git clone /path/to/repo/owned/by/other ./here
fatal: detected dubious ownership in repository at '/path/to/repo/owned/by/other'
To add an exception for this directory, call:
git config --global --add safe.directory /path/to/repo/owned/by/other/.git
Running this git config
command effectively fixes the problem, but (for reasons I do not care to explain here) I would like to be able to clone the repository without modifying the git config file.
The git man page talks about an option -c
that lets users overwrite git config options when running git commands:
man git
...
-c <name>=<value>
Pass a configuration parameter to the command. The value given will override values from configuration files. The <name> is expected in the same format as listed by git config (subkeys separated by dots).
...
So I tried:
git -c safe.directory=/path/to/repo/owned/by/other/.git clone /path/to/repo/owned/by/other ./here
but I still get the dubious ownership error. I tried different variations of the above command but without success.
Thank you for your help.
Upvotes: 2
Views: 150
Reputation: 94827
Found an explanation and a solution at https://lore.kernel.org/all/[email protected]/T/ . The problem is that upload-pack
doesn't have access to the config values passed to git -c
, they must be explicitly passed to upload-pack
. Try this:
git -c safe.directory=/path/to/repo/owned/by/other/.git clone -u 'git -c safe.directory="/path/to/repo/owned/by/other/.git" upload-pack' /path/to/repo/owned/by/other ./here
Can be simplified to
git -c safe.directory="*" clone -u 'git -c safe.directory="*" upload-pack' /path/to/repo/owned/by/other ./here
I tried and that works for me. If that doesn't work for you try the solution from https://lore.kernel.org/all/[email protected]/ with upload-pack-safe
shell script.
Upvotes: 2
Reputation: 178
You can temporarily point Git to a non-existent global config file -
GIT_CONFIG_GLOBAL=/dev/null git -c safe.directory=/path/to/repo/owned/by/other clone /path/to/repo/owned/by/other ./here
Another approach, ignoring ownership checks for this operation-
GIT_TEST_ASSUME_DIFFERENT_OWNER=true git clone /path/to/repo/owned/by/other ./here
Upvotes: 0
Reputation: 326
The command you used is almost right, but it has a slight syntax mistake. You need to apply the safe.directory
setting to the main repository directory, not just the .git
.
git -c safe.directory=/path/to/repo/owned/by/other clone /path/to/repo/owned/by/other ./here
Upvotes: 0