Is pushing a symbolic link to git a bad practice?
Asked Answered
N

2

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.

Newspaperman answered 30/6, 2015 at 21:43 Comment(4)
@SeanBright how so? en.wikipedia.org/wiki/Symbolic_link#Microsoft_WindowsVasomotor
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?Cachexia
@Vasomotor - Like so: https://mcmap.net/q/46993/-git-symbolic-links-in-windowsKibitka
There's an argument to be made that you shouldn't be using symlinks at all (harmful.cat-v.org/software/symlinks) Of course, I use them everywhere ;)Eligibility
C
13

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.

Curve answered 20/9, 2019 at 16:2 Comment(6)
I was considering more about bad practice and not about if it is doable.Aphyllous
@Aphyllous 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.Curve
@Aphyllous I have edited the answer to emphasize the points you are after.Curve
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 :)Aphyllous
Does a submodule considered outside a repo?Tucana
@Tucana 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.Curve
D
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.

Donata answered 28/5, 2020 at 11:21 Comment(2)
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.Airily
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.Rooted

© 2022 - 2024 — McMap. All rights reserved.