How to Stop macOS from Creating ._ Files on an External Drive with an APFS Workspace

If you keep your code on an external drive and develop directly from there on macOS, you may notice annoying files such as ._package.json or ._README.md showing up next to your real files. These ._* files can pollute Git status, clutter your editor, and make search results noisy.

If your drive is formatted as exFAT, this is usually not caused by your project. It is a compatibility behavior from macOS. Hiding or ignoring these files can reduce the noise, but it does not stop them from coming back.

Requirements

The goal is usually straightforward:

  • Keep projects on the external drive.
  • Stop ._* files from being created during normal development work.
  • Use one stable path for future repositories.
  • Avoid migrating old projects if re-cloning is easier.

As a temporary mitigation, you can add this to .gitignore:

._*

You can also hide ._* files in your editor. That helps with visibility, but it is still only a workaround.

Solution

The reliable fix is to stop developing directly inside the exFAT directory and instead create an APFS sparse image on the same external drive. Then use that mounted APFS volume as your development workspace.

Why this works:

  • exFAT does not natively support some macOS metadata.
  • macOS stores that metadata in separate ._filename sidecar files.
  • APFS supports that metadata natively, so those sidecar files usually stop appearing in normal development workflows.

In this setup, the mounted volume is named github, so all future repositories can live under:

/Volumes/github

1. Create the APFS sparse image

This command creates an APFS sparse image file on the external drive and names the mounted volume github:

cd /Volumes/Elements/code

hdiutil create -size 200g -type SPARSE -fs APFS -volname github "/Volumes/Elements/code/github-workspace.sparseimage"

What the main flags mean:

  • -size 200g sets the maximum size to 200GB.
  • -type SPARSE creates a sparse image, so it grows as needed.
  • -fs APFS uses APFS inside the image.
  • -volname github makes the mounted path appear as /Volumes/github.

2. Mount the workspace

After creating it, mount it with:

hdiutil attach "/Volumes/Elements/code/github-workspace.sparseimage"

Once mounted, you will get a new working path:

/Volumes/github

From this point on, new projects should go there instead of the original exFAT directory.

3. Clone new repositories into /Volumes/github

For example:

cd /Volumes/github
git clone https://github.com/openHacking/PyDeskUI.git

You can also create future project folders there:

cd /Volumes/github
mkdir my-next-project

4. When to mount and unmount it

You can think of the image as a dedicated development disk.

Before you start working, mount it:

hdiutil attach "/Volumes/Elements/code/github-workspace.sparseimage"

When you are done for the day and no longer need access to /Volumes/github, unmount it:

hdiutil detach "/Volumes/github"

In practice:

  • attach means turning your development workspace on.
  • detach means safely disconnecting it when you are done.

If unmounting fails, an app is usually still using files under /Volumes/github. Close VS Code, Finder windows, or terminal tabs that point to that path, then try again.

5. Will ._* files still appear?

If you keep working directly in the exFAT location, such as:

/Volumes/Elements/code/github/some-project

then ._* files may still come back.

If you work inside the mounted APFS workspace instead, such as:

/Volumes/github/some-project

then those files will usually stop appearing during normal development.

Summary

The real cause of ._* files is usually not your codebase. It is the way macOS stores metadata on exFAT external drives.

The practical fix is not to keep fighting those files inside each repository, but to move your development workflow into an APFS environment. For external-drive users, an APFS sparse image is a very useful compromise:

  • You do not need to reformat the whole drive.
  • You can still keep everything on the external disk.
  • New repositories live under one clean path.
  • You can reduce or avoid recurring ._* files at the source.

If you do not need to migrate old repositories, the simplest setup is to keep the old exFAT folders as archive storage and clone all new projects into /Volumes/github.

Comments