Managing Dotfiles with GNU Stow

mbvissers.eth
Quick Programming
Published in
3 min readJan 19, 2024

--

Using GNU Stow to manage your dotfiles on GitHub.

Photo by Drew Beamer on Unsplash

Sharing your Linux configuration files can be useful for both yourself and for anyone you interact with. If you’ve ever updated your own system you might’ve checked other people’s dotfiles already. But how do you actually set up such a repo?

I personally was just done setting up a nice little Neovim setup, my VSC is properly set up, and my themes are aligned. But just when I think I’m finished, I get a new laptop from work. Woe is me.

What are Dotfiles

If you’re on Linux, you’re probably familiars with dotfiles. If not, read on.

Dotfiles, generally, are files that start with a dot. For example the .nvmrc , .zshrc , .bashrc files you often see in Linux. Or maybe the more familiar .gitignore and .gitkeep files every developer knows.

True dotfiles are often used for configuration files. Either project-wide or system-wide (like zshrc ).

But the term dotfiles has been expanded in some Linux communities to mean all config files. Such as ~/.config/nvim/* .

People that are into ‘ricing’ their systems often have their dotfile repositories publicly on GitHub. And I love that. You can learn from their Vim configurations, copy their transparent windows or tiling animations without having to ask for any details.

But how would you easily start your own dotfile repository? It might be useful to quickly change configs (using Git branches), or quickly setting up a new system (as I will be doing soon…).

You could opt for a very labor intensive method of just copying and pasting configs around. but another way is to use symbolic links in Linux. But running ln -s ~/dotfiles/nvim ~/.config/nvim for every folder you want saved, and then having to replace them when you want them back. But this might be a bit of a hassle.

Symbolic links, or symlinks, are the way that Linux implements shortcuts like you have in Windows. You can have a symlink on your desktop that points to a configuration file. And then each change you make at ~/dotfiles/* will be reflected in ~/.config/*.

Notice the little arrows in the top-right corner of my i3 config folders?

This is very useful, but for what we need it might get annoying having to create your own symlinks for each folder or file you want in your dotfile repository.

Stow

Thankfully, smarter people than me at GNU have created Stow.

With stow we don’t have to create our symlinks by ourselves.

We start off by creating a folder called dotfiles in our Home (~) directory. In this folder we can run git init, set up our version control, and after that, the real fun begins.

Installing Stow

You can easily install Stow on most Linux distributions. For example on Arch you just run:

sudo pacman -S stow

And Stow should be installed for you.

Using Stow

cd into the newly made directory and create a few directories in which we can move the config files. Let’s use our Neovim config as an example. Create the following structure.

dotfiles/
├─ nvim/
│ ├─ .config/

It might look weird for now, but trust me. Now we can cd back to our home directory and we can mv the Neovim config into the newly made folders.

mv ~/.config/nvim ~/dotfiles/nvim/.config/nvim

This should result in the following folder structure.

dotfiles/
├─ nvim/
│ ├─ .config/
│ │ ├─ nvim/
│ │ │ ├─ init.lua

Now for the magic, we can cd back into the dotfiles directory and call stow to create the symlink in ~/.config for us.

cd ~/dotfiles
stow nvim

The next step is to do this with all the other folders you want saved in your dotfile repository.

Conclusion

If you want, you can find my (very incomplete) dotfiles here.

Thank you so much for reading and have an excellent day.

I am not a part of the Medium partner program anymore so I don’t earn anything from this. Give me a follow and help me spread knowledge for free.

Follow me on Twitter (X) and here on Medium to keep up with me and my projects.

--

--

mbvissers.eth
Quick Programming

I occasionally write about programming. Follow me on Twitter @0xmbvissers