How I manage dotfiles with stow and git
Published on 23 Dec 2020
TLDR; it is a tool to create symlinks from a directory to another directory. See the demo.
Tree
Introduction Jump to heading
I like to keep my development workflow equivalent in all my machines. This includes my aliases, vim config, etc. I also need to have diffing so that I can easily see the changes I've made and a history of the changes I've made in case I want to revert back. Having the dotfiles in a repo solves these two issues.
However, I still needed a way to sync the dotfiles in my local file system to the repo and vice versa. This is where stow
comes in handy.
How stow solved my problem? Jump to heading
stow
is symlink farm manager. It manages symlinks from two different directories. When I make changes in the dotfiles
directory, it will also reflect onto the local file system.
How to install? Jump to heading
Arch Linux Jump to heading
sudo pacman -S stow
OSX Jump to heading
brew install stow
Methods I've used in the past Jump to heading
Copy Paste Jump to heading
I've used this method in the past because I wanted something quick and dirty for just one file. Once you start doing copy pasting more than once, it gets really troublesome to keep track of the file that is in your system with the one in your dotfiles repo.
I was using ranger to help with the copy pasting. Even then, it lacks the diffs that version control provides.
Manually symlinking Jump to heading
Symlinking is the way to go. You create a symlink from the dotfile in your repo to your local file system. This way you are only managing 1 file only and it is version control tracked. However, doing this for every file is very tedious and error prone.
Edge Cases: What happens when ... Jump to heading
Creating a file in the local file system Jump to heading
It will automatically create a file in the source directory which is the dotfiles directory.
Creating a file in the repo Jump to heading
Similar like the previous step, it will create file in the target directory which is the local file system.
Conclusion Jump to heading
Having the dotfiles in a version control makes experimenting with config files easier and safer. I truly recommend stow
to sync between the two directories. Let me know what you think or if you have any suggestions.