Search code examples
gitsymlinkgit-config

git: how to ignore symlinks?


I have a local git repo in a directory that contains soft links (Linux), and I'd like to ignore those links so that git status etc. won't bother about these links. I am using git v2.34.

This answer proposes to set core.symlinks to false, which I did in the local .git/config and cross-checked by means of

$ git config --get core.symlinks
false

Despite of that setting, git is still showing the links with git status. I know I can add all them symlinks to .gitignore by hand (or by means of a script for that matter).

So what part am I missing?

The documentation of .gitignore has only two mentions of "symbolic link" which don't answer my question, so presumably it's not a feature of git as of v2.32 ?


Solution

  • Git doesn't have a built-in feature to ignore symlinks. If there are paths that you don't want to include in your repository, whether those are symlinks or not, then you can specify them in .gitignore, and Git will ignore them if they are untracked. You will have to list them explicitly by filename, since the .gitignore file doesn't provide a way to select different file types. You can, however, ignore a directory with a trailing slash (e.g., foo/) to ignore the directory and its entire contents.

    If they are already tracked, then you'll want to use git rm --cached to remove them from the index so that they are untracked, and then ignoring them will be effective. Git doesn't offer a way to ignore tracked files.

    In general, you want to avoid modifying core.symlinks. That value is an internal value determined by Git to remind itself whether the OS and file system in question support symlinks (since, on Windows, symlinks may require elevated permission you may not have). It isn't designed to be modified by the user, and it won't result in the behaviour you want anyway.