Getting symlinks to work with a git clone on Mac

Featured image for sharing metadata for article

Yesterday I was working with one of my colleagues, who had an issue in one of their Git repos where a symbolic link (symlink) wasn't resolving correctly.

The problem

This turned out to be due to how MacOSX will by default set core.symlinks=false, as a security measure (via).

This means that when a symbolic link is part of a cloned / pull'd repo, then instead of seeing i.e.:

# expected behaviour
$ ls -al bin/eksctl
lrwxrwxrwx 1 jamie jamie 19 Sep 30 13:18 bin/eksctl -> .eksctl-0.190.0.pkg

Then we will instead see:

# actual behaviour
$ ls -al bin/eksctl
-rw-r--r-- 1 jamie jamie 19 Oct  1 08:07 bin/eksctl
$ cat bin/eksctl
.eksctl-0.190.0.pkg

Solution

So how do we unpick this?

First, we need to make sure Git creates symlinks:

$ git config core.symlinks true

Once we run this, we then see that Git has detected there's a "type change":

$ git status
On branch main
Your branch is up to date with 'origin/main'.

Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
	typechange: bin/eksctl

However, we're still seeing no symlinks:

$ ls -al bin/eksctl
-rw-r--r-- 1 jamie jamie 19 Oct  1 08:07 bin/eksctl
$ cat bin/eksctl
.eksctl-0.190.0.pkg

To resolve this, we can then use git checkout i.e.

git checkout bin/eksctl

This then forces Git to re-checkout that file, with the correct type:

$ ls -al bin/eksctl
lrwxrwxrwx 1 jamie jamie 19 Oct  1 09:00 bin/eksctl -> .eksctl-0.190.0.pkg

And now our symlinks will start working again πŸ‘πŸΌ

This will need to be done for any other typechanges that Git detects.

Written by Jamie Tanna's profile image Jamie Tanna on , and last updated on .

Content for this article is shared under the terms of the Creative Commons Attribution Non Commercial Share Alike 4.0 International, and code is shared under the Apache License 2.0.

#blogumentation #git #mac.

This post was filed under articles.

Interactions with this post

Interactions with this post

Below you can find the interactions that this page has had using WebMention.

Have you written a response to this post? Let me know the URL:

Do you not have a website set up with WebMention capabilities? You can use Comment Parade.