Developer and Writer

How I manage my dotfiles using GNU Stow

How I manage my dotfiles using GNU Stow
Photo by Jack Michaud / Unsplash

I have a lot of dotfiles.

I have dotfiles for my:

I also like to keep things consistent across my different machines. So, I make sure to store all my dotfiles and configurations on GitHub.

But in the past, to keep things in sync, I always had to do something like this:

cp dotfiles/.zshrc ~/.zshrc

I had to do it for every single file or folder I had. This got very annoying until I discovered GNU Stow.

Introducing GNU Stow

GNU Stow is a symlink farm manager, which means it helps you store all your configuration files in one common location.

So when you "stow" a file, it will create a symlink between your file and an identical file in our home directory.

But remember that it will follow the same folder structure as the file. So, if you have a file like:

./dotfiles/randomfolder/.zshrc

Then, stow will symlink to the directory:

~/randomfolder/.zshrc

The main lesson here is that you should organize your dotfiles in the same way you would organize them in your home folder.

For example, this is the structure of my dotfiles:

Using GNU Stow

Let's first install Stow. If you're on MacOS, then installing it is as simple as:

brew install stow
💡
If you're on Linux, you can find it in the package managers of most GNU/Linux distributions with the name stow.

I would then suggest creating a folder in your home directory called dotfiles.

mkdir ~/.dotfiles

This is where all our common configurations will reside. As an example, we would create a file named random.txt.

cd ~/.dotfiles
touch random.txt 

Finally, I just have to run the command stow . to symlink my files to my parent directory.

If all went well, you should find a random.txt file in your home directory.

💡
Don't forget to version control your dotfiles. So run that git init there.

Extra Tricks

Ignore Files

If you version control your dotfiles, then you'd have a .git directory in your folder.

You'd probably be concerned about Stow symlinking the .git folder, but fear not Stow will automatically ignore the .git folder.

This is the .git folder is specified in the default stow ignore file.

The default stow ignore file looks like this:

GNU Stow Official Docs

If you want to overwrite it, then you can create a local stow ignore file called .stow-local-ignore.

For example, I have Makefile with some useful commands, and I don't want to stow to symlink it.

I can create a .stow-local-ignore file and specify my Makefile there.

echo "Makefile" >> .stow-local-ignore
Beware, if you create a .stow-local-ignore file, then it will override all the default settings. Make sure to specify any other defaults you'd want to have, such as .git or README.md,

If you'd like to get rid of all the symbolic links that Stow created in your home folder, you can do that with the following command:

stow -D .

Closing Thoughts

GNU Stow has fundamentally changed the way I manage my dotfiles.

No more do I have to copy files around.

Symlink is the answer.

GNU Stow is the answer.

Thanks for reading.

Member discussion

-->