core.symlinks configuration without automatic fallback in restricted environments
0 reputation · 07 Aug 2021, 19:24 UTC
0 reputation · 07 Aug 2021, 19:24 UTC
Ensure that a repository containing symbolic links can be cloned and checked out identically on both developer workstations and production servers that lack the privilege to create filesystem symlinks.
On systems where the user cannot create symlinks (e.g., Windows without Developer Mode, Linux containers missing CAP_SYS_ADMIN), Git aborts the clone or checks out plain files when core.symlinks is true, because it does not automatically fall back to storing links as ordinary files. This behavior makes the outcome dependent on the host’s permissions and can lead to divergence between environments.
core.symlinks behavior without requiring privileged users?34775 reputation · 08 Aug 2021, 04:56 UTC
Git does not automatically fall back to plain files when a symlink cannot be created. If core.symlinks is true and the process lacks the necessary privileges, the checkout will abort or leave the working tree incomplete. To guarantee identical checkouts across developer workstations and production servers that cannot create symlinks, you must disable symlink creation explicitly.
core.symlinks to false on every host that cannot create symlinks. This can be done globally or per‑repository.
git config --global core.symlinks falsegit config --local core.symlinks false (writes to .git/config)git clone . Symlink entries in the commit will be checked out as ordinary files containing the target path.
post-checkout hook that turns plain‑text symlink files into real symlinks.
Running git config --local core.symlinks false inside the repository writes the setting to .git/config. This file is part of the repository’s metadata and will be shipped to any clone, so all users on that machine will inherit the non‑symlink behavior without requiring privileged access. It does not affect users who clone the repo on machines that can create symlinks unless they override locally.
core.symlinks on a system that supports symlinks will break tools that rely on real symlinks. Use this setting only on restricted hosts.
These recommendations assume Git 2.30+ and a standard POSIX or Windows environment. Verify by running:
git config --local core.symlinks
# Should output "false"
After cloning, check a symlink entry:
git ls-tree HEAD | grep symlink
# Should show a blob entry, not a gitlink
To tailor the hook conversion step precisely, what is the exact pattern used for symlink target files (e.g., file extension or naming convention) in your repository?
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.