Sane dotfile management with GNU stow
I have always struggled to figure out how to efficiently deal with dotfiles for my operating system when it came to managing multiple machines/servers. There was a set of dotfiles that, if easily and reliably available across all my machines, would make setting up a new machine way easier. For an individual machine, there would be differences that shouldn't be shared though. There's seemingly no limit to the number of solutions that exist to address this sort of problem.
What I've Tried
I've used hacky methods, like copying files to the new machine on a USB during setup. This was unreliable for keeping multiple machines on the same core dotfiles, but it works in a pinch. I tried Chezmoi, a huge project that, as far as I can figure out, was like a wrapper around the Ansible project. This added some improvements such as GitHub committed changes and made it easier to roll dotfiles out to new machines. The downside, in my mind, was always the project's complexity. I didn't want to be left stranded if support stopped. I wanted my setup to be simple enough that my brain could grok it and I could be confident that I understood how all the pieces worked.
Enter GNU stow
`stow` works by creating symbolic links to files within a given folder that it's run in linking them to your home folder in the same hierarchy. This allows the stow-managed dotfiles folder to be placed under git change control. That makes cloning the repo simple to get a new machine setup. It's a simple utility program, unlike more feature-rich programs, but it does one thing and does it well. I still can't remember how I stumbled onto this utility, but it was a lightbulb moment.
In my home folder, I have a folder with all the dotfiles called ... wait for it...dotfiles. Inside that folder, there are several files and folders:
If we run `stow .` from the top-level of the dotfiles folder, it will create symbolic links to all those files into my `home` folder, recreating the same structure. Here's what my home folder would look like after running that command:
**NOTE:** `stow` is smart enough to avoid making links for typical git files like `README` or `.git`!
Overall, this was a simple enough setup that keeps all my dotfiles version-controlled in git, provides a simple way to set up dotfiles on new machines, and effortlessly can keep existing machines in sync with a helper script or alias to run `git pull && stow .`. For machines that need to deviate or are using one-off dotfile settings, I can always make new git branches.
© 2024-present by Katie Keller.
Content of this website is licensed under CC BY-NC-SA 4.0.
Crafted with 💖. Built with gempost.