This is just a quick one really to share how I’ve managed to keep my dotfiles organised (something I’ve always struggled with) and in sync between machines using GNU Stow. I found this trick quite useful so thought you might be interested in seeing this too.
The problem I’ve come across in the past is, I’ll see an interesting tool, try it out, configure it on that machine and then move on to the next thing without carrying those settings with me. The end result is different configs on different machines for different tools and applications all managed separately, and an inconsistent dev workflow.
Then I heard about and tried Gnu Stow. It’s basically a command line tool to help you manage symlinks, which you can use to colocate all of your files in a version controlled repo. So instead of having your dotfiles scattered around your $HOME directory, you’ve got symlinks of those files scattered there instead, while the real files are in one place, wherever you’d prefer to keep them.
- Set up a folder where you’ll store your dotfiles, initialise it with git and push it up to your github (or whoever you use for your version control).
- Now, move your config file or folder to your new dotfiles folder so that it’s top-level folder within the new repo matches the name of the tool, followed by that files same path from
$HOME.- For example if you want to move your
~/.zshrcfile you’d move it like thismv ~/.zshrc ~/dotfiles/zsh/.zshrc - If you wanted to move ./config/nvim and all of its contents you'd move it to
mv ~/.config/nvim ~/dotfiles/nvim/.config/nvim
- For example if you want to move your
- At this point, if you were to restart your terminal, you’d see that all of the nice cool things you’ve added over time have disappeared. You’ve just got the barebones initial setup. So now you need to use GNU Stow to say “Hey, create symlinks for these files and use the same paths as we’re using here in the repo”:
And that’s it.
This creates a symlink between the files in dotfiles/zsh and their respective locations on your machine. If you restart your terminal again, you’ll see your config all back together.
Now that you’ve got a version controlled repository you can add, change, delete things from your dotfiles folder and use git to keep everything in sync and consistent regardless of where you’re working from.
For a much more comprehensive explanation of this, run man stow from your terminal.
