Git: unable to create symlink (File name too long)

Here’s a solution that doesn’t require you to go back and fix commits.
After all it may not be feasible if the repo is remote or shared.
It uses core.symlinks=false. You said you tried this but did not say when.
You must do it before a checkout, which a normal clone does by default.
So you must clone with the –no-checkout option.

git clone --no-checkout the-repo tmp-clone-dir
cd tmp-clone-dir
git config core.symlinks false
git checkout
cp the-problem-file the-problem-file.bak # make a backup
git rm the-problem-file
git commit -m 'Removed problem file pretending to be a symlink' the-problem-file
mv the-problem-file.bak the-problem-file # restore the backup; now it will be of type file
git commit -m 'Added back the problem file - now with the correct type' the-problem-file
git push origin master
cd ..
\rm -rf tmp-clone-dir  # IMPORTANT

That last step is important because you don’t want to do more work in a repo with core.symlinks=false. It’s just asking for trouble.

The above assumes that you want the file to be a file not a symlink. If it was meant to be a symlink then you’d stop after the first commit, remove the tmp-clone-dir and go back to your normal repo checkout to make the symlink and commit it.

The benefit in this method is that you don’t break any related clones and branches as it preserves history. The downside to this is that the broken commit is still there and will cause problems for anyone if they attempt to use that particular bad commit.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)