gitfilemklink

mklink + git issues - why wont it let me link?


I'm trying to make a hard link of my .bash_profile into my dotfiles repo on my HDD. I can't get it to work and I don't know why.

mklink - type - link - target

mklink /H "F:Documents\Repos\dotfiles\.bash_profile" "C:\Users\name\.bash_profile"

This returns the following message "The system can't move the file to a different disk drive"


Solution

  • Because of the nature of hard links, they cannot be made from one drive to another. Here's Microsoft's documentation on the subject.

    Every file is a hard link. A hard link is a name pointing to a piece of data (a file) on a hard drive. For most files there's just one name pointing at one file. When you make a hard link to an existing file you're creating another file path that points at the same file. A hard link points at the data, not at the name.

    This is why hard links can only be made on the same drive, drives cannot reference the underlying files on another drive without using the name. To link to another drive you need to use a symbolic link from one filename to another.