title: Directory symlinks change to file symlinks after pushing and pulling from Git
body: <p>Directory symlinks created in a Git repo on Windows for some reason change into File symlinks once pushed to Git and re-cloned. This results in a "The directory name is invalid" error. </p>
  
  <p>However, this ONLY happens when the symlink contains more than one subdirectory in its path. They continue to work fine if there's only one subdirectory. Also, they all still work fine in a Bash shell.</p>
  
  <p>Here's the list in the original repo:</p>
  
  <pre><code>05/01/2019  07:50 AM &lt;SYMLINKD&gt; ACN [..\..\acn\Installed]
  05/01/2019  08:00 AM &lt;SYMLINKD&gt; ACNProxy [..\..\acnproxy\bin]
  04/30/2019  01:29 PM &lt;SYMLINKD&gt; API [..\swupdate-2\bin]
  05/01/2019  08:24 AM &lt;SYMLINKD&gt; AnalyticsPlugin [..\..\..\analyticsinstallerplugin]
  05/01/2019  08:08 AM &lt;SYMLINKD&gt; Encryption [..\protocols\trunk\Encryption]
  05/01/2019  08:17 AM &lt;SYMLINKD&gt; HelpFiles [..\helpwwb6]
  05/01/2019  08:34 AM &lt;SYMLINKD&gt; PrePackagedDatabase [..\wwb6database]
  05/01/2019  09:34 AM &lt;SYMLINKD&gt; ToastNotifications [..\toastnotifications]
  05/01/2019  08:01 AM &lt;SYMLINKD&gt; acnComponent [..\..\..\acn_component]
  05/01/2019  07:45 AM &lt;SYMLINKD&gt; dante_lic_mac [..\dante_mac_fix\WWB_compressed_lic_info_files]
  05/01/2019  08:05 AM &lt;SYMLINKD&gt; devCategory [..\..\..\devicedescriptionfiles\devCategory]
  05/01/2019  08:10 AM &lt;SYMLINKD&gt; shared [..\..\frequencycompat\FrequencyCompatibilityCalculator]
  05/01/2019  09:26 AM &lt;SYMLINKD&gt; shared [..\..\swupdate\src\shared]
  05/01/2019  08:06 AM &lt;SYMLINKD&gt; skuConversion [..\..\..\skuconversion\src]
  </code></pre>
  
  <p>After pushing the symlinks to the remote Git server and recloning the repo, those symlinks that are pointing to a path that has more than one subdirectory listed were changed into File symlinks:</p>
  
  <pre><code>05/01/2019  09:28 PM &lt;SYMLINK&gt;  ACN [..\..\acn\Installed]
  05/01/2019  09:28 PM &lt;SYMLINK&gt;  ACNProxy [..\..\acnproxy\bin]
  05/01/2019  09:28 PM &lt;SYMLINK&gt;  API [..\swupdate-2\bin]
  05/01/2019  09:28 PM &lt;SYMLINKD&gt; AnalyticsPlugin [..\..\..\analyticsinstallerplugin]
  05/01/2019  09:28 PM &lt;SYMLINK&gt;  Encryption [..\protocols\trunk\Encryption]
  05/01/2019  09:28 PM &lt;SYMLINKD&gt; HelpFiles [..\helpwwb6]
  05/01/2019  09:29 PM &lt;SYMLINKD&gt; PrePackagedDatabase [..\wwb6database]
  05/01/2019  09:28 PM &lt;SYMLINKD&gt; ToastNotifications [..\toastnotifications]
  05/01/2019  09:28 PM &lt;SYMLINKD&gt; acnComponent [..\..\..\acn_component]
  05/01/2019  09:28 PM &lt;SYMLINK&gt;  dante_lic_mac [..\dante_mac_fix\WWB_compressed_lic_info_files]
  05/01/2019  09:28 PM &lt;SYMLINK&gt;  devCategory [..\..\..\devicedescriptionfiles\devCategory]
  05/01/2019  09:28 PM &lt;SYMLINK&gt;  shared [..\..\frequencycompat\FrequencyCompatibilityCalculator]
  05/01/2019  09:28 PM &lt;SYMLINK&gt;  shared [..\..\swupdate\src\shared]
  05/01/2019  09:28 PM &lt;SYMLINK&gt;  skuConversion [..\..\..\skuconversion\src]
  </code></pre>
  
  <p>Can anyone explain this behavior?</p>
  
  <p>In a Bash shell, all symlinks look identical (and function) in both the original and cloned repo:</p>
  
  <pre><code>lrwxrwxrwx 1 ******* 1049089 17 May  1 21:28 ./wwb6/API -&gt; ../swupdate-2/bin
  lrwxrwxrwx 1 ******* 1049089 46 May  1 21:28 ./wwb6/dante_lic_mac -&gt; ../dante_mac_fix/WWB_compressed_lic_info_files
  lrwxrwxrwx 1 ******* 1049089 19 May  1 21:28 ./wwb6/datastorage/ACN -&gt; ../../acn/Installed
  lrwxrwxrwx 1 ******* 1049089 18 May  1 21:28 ./wwb6/datastorage/ACNProxy -&gt; ../../acnproxy/bin
  lrwxrwxrwx 1 ******* 1049089 22 May  1 21:28 ./wwb6/datastorage/libdatastorage/acnComponent -&gt; ../../../acn_component
  lrwxrwxrwx 1 ******* 1049089 43 May  1 21:28 ./wwb6/datastorage/libdatastorage/devCategory -&gt; ../../../devicedescriptionfiles/devCategory
  lrwxrwxrwx 1 ******* 1049089 26 May  1 21:28 ./wwb6/datastorage/libdatastorage/skuConversion -&gt; ../../../skuconversion/src
  lrwxrwxrwx 1 ******* 1049089 29 May  1 21:28 ./wwb6/Encryption -&gt; ../protocols/trunk/Encryption
  lrwxrwxrwx 1 ******* 1049089 54 May  1 21:28 ./wwb6/FrequencyCompatibility/shared -&gt; ../../frequencycompat/FrequencyCompatibilityCalculator
  lrwxrwxrwx 1 ******* 1049089 11 May  1 21:28 ./wwb6/HelpFiles -&gt; ../helpwwb6
  lrwxrwxrwx 1 ******* 1049089 33 May  1 21:28 ./wwb6/Installation/Mac/AnalyticsPlugin -&gt; ../../../analyticsinstallerplugin
  lrwxrwxrwx 1 ******* 1049089 15 May  1 21:29 ./wwb6/PrePackagedDatabase -&gt; ../wwb6database
  lrwxrwxrwx 1 ******* 1049089 25 May  1 21:28 ./wwb6/SWUpdate/shared -&gt; ../../swupdate/src/shared
  lrwxrwxrwx 1 ******* 1049089 21 May  1 21:28 ./wwb6/ToastNotifications -&gt; ../toastnotifications
  </code></pre>
  
  <p>Note that all this was done on a Windows 10 machine. However, the remote repository is located on a Linux server. I deliberately do not have Administrators rights on the Windows machine, because the developers don't have those rights either and the symlinks should work for them.</p>
  
  <p>To get symlinks to work in Windows, I did the following:</p>
  
  <ul>
  <li>Enabled symbolic link support when installing Git Bash;</li>
  <li><p>Added the following entries to the user's .bash_profile:</p>
  
  <blockquote>
    <p><code>export MSYS=winsymlinks:nativestrict</code></p>
    
    <p><code>export CYGWIN=winsymlinks:nativestrict</code></p>
  </blockquote></li>
  <li><p>Enabled symbolic link support in Git:</p>
  
  <blockquote>
    <p><code>git config --global core.symlinks true</code></p>
  </blockquote></li>
  <li><p>Assigned the SeCreateSymbolicLinkPrivilege permission by adding the user to the Create Symbolic Links policy using the Group Policy editor;</p></li>
  <li><p>Ensured the user is allowed to evaluate Local to Local symbolic links:</p>
  
  <blockquote>
    <p><code>fsutil behavior query symlinkevaluation</code></p>
  </blockquote>
  
  <p>...and ran the following command as Administrator when that is not the case:</p>
  
  <blockquote>
    <p><code>fsutil behavior set symlinkevaluation L2L:1</code></p>
  </blockquote></li>
  <li><p>For good measure, included the -c core.symlinks=true switch to the git clone command.</p></li>
  </ul>
  
  <p>After making all those changes, creating and traversing directory symlinks works fine in Windows without the user having to be in the Local Admin group. Until they've been pushed to Linux and re-downloaded that is.</p>
  
  <p>Update:
  The symlinks that changed type from SYMLINKD to SYMLINK after a clone point to directories inside submodules. The root directory of a submodule is created when the container project is cloned, but the contents isn't pulled down until after the clone of the container project (where the symlinks live) has completed:</p>
  
  <pre><code>git clone --recursive -c core.symlinks=true ssh://&lt;server&gt;:7999/&lt;repo&gt;
  </code></pre>
  
  <p>It appears Windows does not recreate Directory symlinks when the target does not yet exist. It creates them of type File symlink instead. This DOES work from the Windows command line though (as it does in Linux):</p>
  
  <pre><code>mklink /d symlink ..\&lt;some non-existing directory&gt;\&lt;another non-existing directory&gt;
  </code></pre>
  
  <p>...works fine.</p>
  
  <p>My current workaround is to simply delete and restore them:</p>
  
  <pre><code>$ find . -type l -delete
  $ git checkout .
  Updated 14 paths from the index
  </code></pre>
  
  <p>Would prefer a fix for this though.</p>