8

Is there a way to make git handle a symlink as if it was a file. If I just normally add a symlink like git add symlink, git just stores/controlls the path to the file, not the linked file.

Is it possible to make git handle a symlink as if it was the linked file itself?

nath
  • 5,430
  • 9
  • 45
  • 87
  • Why use a symlink then? Why not create a copy of the file in the first place? IOW, what's the use case? If it is a file outside the git repo, why not move the file into the git repo and plant a symlink to it at its former location? – NickD Nov 19 '19 at 22:52

1 Answers1

6

Sounds like you want a hard link

ln sourcefile /some/git/repo/targetfile

Only any good if the source and target locations are within the same file system. Otherwise you’ll have to settle for a copy or a symlink.

A symlink is a reference to a file. A hard link is another name for an existing inode.

There are numerous resources on the web that explain in more detail.

I’m not using a special syntax to do with hard links. The man page for ln is a good place to look for the variations on syntax available.

bxm
  • 4,561
  • 1
  • 20
  • 21
  • 1
    THX for the answer, this solved my issue! Was it possible to include some more information on the technical difference of a `symlink` achieved with `ln -s` and a hardlink, created with `ln` without option? Also I was used to use `ln` with `cd` to the directory the link was to be created. In your answer you use the approach from the other side. `cd` into the directory where the `sourcefile` is and add the link to the `sourcefile`. Is this due to the technical difference between a `symlink` and a `hardlink`? – nath Nov 20 '19 at 03:03
  • Added some detail and suggestions for further reading. – bxm Nov 20 '19 at 08:24