12

I'm unsure of whether or not pushing symbolic links to a git repo is a bad practice or not. Is there any risk or bad reason to do so?

I haven't seen a good answer. If anyone has a good resource or explanation please share.

Alec Walczak
  • 427
  • 1
  • 5
  • 17
  • 1
    @SeanBright how so? https://en.wikipedia.org/wiki/Symbolic_link#Microsoft_Windows – Eluvatar Jun 30 '15 at 21:50
  • I'm inclined to say it's a bad idea, because it probably is, but it might depend on the situation. Why are you wanting to? – Luke Cousins Jun 30 '15 at 21:50
  • @Eluvatar - Like so: http://stackoverflow.com/questions/5917249/git-symlinks-in-windows – Sean Bright Jun 30 '15 at 21:51
  • There's an argument to be made that you shouldn't be using symlinks at all (http://harmful.cat-v.org/software/symlinks) Of course, I use them everywhere ;) – fpf3 Aug 19 '20 at 16:15

2 Answers2

11

As long as the symlink references a resource within the same repository, as a relative path, it should be OK (especially now that symlinks are supported on Windows, and no longer require privilege elevation)

The following two cases would not work though, when that same symlink references a resource:

  • inside a repository, but with an absolute path (bad practice)
  • outside the repository with a relative or absolute path (bad practice)

"bad practice" because :Any clone of the repository in a different machine/patform/OS would not be able to access/use those paths.


After that, it depends where the repo (with its symlink) is used.

I mentioned before in "How to add symlink file to a gitlab repo" that a symlink would make a GitLab pipeline fail.

=> "bad practice": the environment where such a repository would be used would fail to run its content.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • I was considering more about **bad practice** and not about if it is _doable_. – lucasvc Sep 21 '19 at 13:26
  • @lucasvc **bad practice** is *precisely* what this answer addresses: if it is outside a repo or with an absolute path, that would be a *bad practice*. If it is used in a pipeline, that would be a bad practice. – VonC Sep 21 '19 at 13:28
  • @lucasvc I have edited the answer to emphasize the points you are after. – VonC Sep 21 '19 at 13:29
  • Well, my opinion was this, but still have my doubts about good or bad practice (from an engineering point of view). But the points are for you :) – lucasvc Sep 22 '19 at 16:25
  • 1
    Does a submodule considered outside a repo? – Rock_Artist Dec 30 '19 at 10:00
  • @Rock_Artist It is a reference to an external repository, composed of a SHA1 entry and the URL of the remote repository (in the `.gitmodules` file): it is a perfectly acceptable good practice. – VonC Dec 30 '19 at 15:28
2

We had arrangements with symlinks in github repositories and from my perspective it is a bad practice:

  1. Code organization is bad. You will see two or more instances of the same files and you need to investigate every time if it is a symlink or a regular file
  2. IDE's don't work well with duplicate files
  3. You can scan for changes in an individual folder, and if no changes are made you can skip certain steps in continuous integration. With symlinks, this is more difficult.

I guess there are other factors as well, but this is what I encountered.

Bogi
  • 2,274
  • 5
  • 26
  • 34
  • I don't understand what you mean by "two or more instances of the same files". You're creating symbolic links to... where? Other files in the repository? I feel like there's a lot of (relatively _narrow_) assumptions made about code organization here that don't really deal with the very _broad_ question asked. – Edward Thomson May 28 '20 at 12:55
  • And what happens to the symlink files when you delete or move the file they reference? How does that get updated with the new path? The implicit reference seems like a bad idea compared to using a language-specific reference such as import/include. – philn5d Apr 09 '22 at 12:47