GNU Stow: the antelope which manages your config files

So, you've just set up your perfect development environment—your Neovim config is finely tuned, tmux is customized to perfection, and your Starship prompt is looking stellar. But then reality hits: you need to replicate this setup on another machine. The idea of manually copying and pasting dotfiles is daunting, and keeping them in sync sounds like a headache.

First things first: if you're going to manage your configuration files properly, you should treat them like any other software project. The best way to do this is by creating a Git repository dedicated to your dotfiles. This allows you to version-control changes, back up your configurations, and share them across multiple devices.

mkdir dotfiles
cd dotfiles
git init

Next, you can add your configuration files and push them to a platform like GitHub:

cp ~/.zshrc .
git add .zshrc
git commit -m "Add .zshrc configuration file"
git push origin main

Now you've successfully shared your dotfiles across multiple machines. However, you don't want to copy all the files every time you pull new changes from the repository. This is where symlinks come into play!

A symlink, or symbolic link, is a special type of file that serves as a reference to another file or directory. Think of it as a shortcut that points to the actual file. When you create a symlink, it appears as if the original file exists in multiple locations, but in reality, there is only one copy. This is incredibly useful because it allows you to keep your files in the Git repository while ensuring they reside in their expected locations, such as:

So symlinks are great but manually creating one for every file can be tedious. Enter GNU Stow, the symlink manager you'll need! With Stow, you can create symlinks recursively for your entire directory. Plus, if there are files you want to exclude—like the .git folder in your dotfiles repository—you can easily ignore them using a .stow-local-ignore file.

Let's install GNU Stow, I'll use Homebrew:

brew install stow

By maintaining the same folder and file structure in your dotfiles repository as in your home directory, you can let GNU Stow do the heavy lifting:

stow -d . -t ~/ .

And just like that, your dotfiles are now symlinked to the correct locations!