I have git repo here: ~/git/myrepo/

then I do:

ln -s ~/external_dir ~/git/myrepo

emacs follows symbolic link when opening the file: ~/git/myrepo/external_dir/somefile.txt

I'd like to prevent it, ideally on a per git repo (dir-locals) basis

following doesn't bring the desired effect:

(setq vc-follow-symlinks nil)


(setq vc-follow-symlinks 'ask)

does not make emacs ask a question when opening a file.

I'm running emacs.28.2

please help

1 Answer 1


I think you misunderstood the purpose of vc-follow-symlinks.

In the situation you described, Emacs doesn't ask anything because the version controlled file ~/git/myrepo/external_dir, which is a symbolic link, is not edited. The file that is edited is ~/external_dir/somefile.txt and is not under version control as long as ~/external_dir is not a Git repository.

By setting vc-follow-symlinks to 'ask, Emacs will prompt you if the target of a symbolic link is under version control.

Example :

ln -s ~/git/myrepo/someotherfile.txt ~/external_dir/someotherlink

~/git/myrepo/someotherfile.txt, the target of the symbolic link ~/external_dir/someotherlink is under version control. Now if you invoke e.g. find-file ~/external_dir/someotherlink, Emacs will prompt you (still assuming vc-follow-symlinks is set to 'ask).

  • ok, I understand.
    – vibrys
    Jun 18, 2023 at 14:30
  • Then, what should I do for emacs not to resolve link from my question? I mean, when I'm in shell and do cd ~/git/myrepo/external_dir, then pwd tells it's in /home/user/git/myrepo/external_dir. I'd like emacs behave the same way.
    – vibrys
    Jun 18, 2023 at 14:37
  • If you invoke find-file ~/git/myrepo/external_dir you will end up in a Dired buffer where the directory name is /home/user/git/myrepo/external_dir. Emacs does behave the same way as the shell. At the end, I don't know how to prevent Emacs from resolving the symbolic link in your situation. Jun 18, 2023 at 17:00
  • Tristan, thank you for your time and explanation. I'll have dig deeper to understand what's going on my site
    – vibrys
    Jun 24, 2023 at 2:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.