Search code examples
windowsgitsymlink

Git symbolic links in Windows


Our developers use a mix of Windows and Unix-based OSes. Therefore, symbolic links created on Unix machines become a problem for Windows developers. In Windows (MSysGit), the symbolic link is converted to a text file with a path to the file it points to. Instead, I'd like to convert the symbolic link into an actual Windows symbolic link.

The (updated) solution I have to this is:

  • Write a post-checkout script that will recursively look for "symbolic link" text files.
  • Replace them with a Windows symbolic link (using mklink) with the same name and extension as dummy "symbolic link"
  • Ignore these Windows symbolic links by adding an entry into file .git/info/exclude

I have not implemented this, but I believe this is a solid approach to this problem.

  1. What, if any, downsides do you see to this approach?
  2. Is this post-checkout script even implementable? I.e., can I recursively find out the dummy "symlink" files Git creates?

Solution

  • You can find the symlinks by looking for files that have a mode of 120000, possibly with this command:

    git ls-files -s | awk '/120000/{print $4}'
    

    Once you replace the links, I would recommend marking them as unchanged with git update-index --assume-unchanged, rather than listing them in .git/info/exclude.