Assertion failed

Sep 29, 2014

Dotfiles, git and stow

Keeping your dotfiles in a git repository can be very handy, but unforunantly it’s generally not a good idea to put your whole home directory in a git repo. To come around this I have seen some people add “*” to gitignore, but that is more of a hack than a proper solution. Another way of doing this is to place all dotfiles in a seperate directory which is in git and symlink back to where they are expected. I would consider this to be a better solution, but it is a lot more work. Installing and maintaining the symlinks can become tedious if the amount of dotfiles managed becomes a little more than a few.

This is where GNU stow comes in. Although it’s not made to keep track of dotfiles, but rather programs manually compiled and installed to /usr/local. But this doesn’t really matter as it will serve well for our purpuse.

Let’s start by creating a directory for dotfiles and initiating a git repository in it. I’m assuming you know how to install the needed tools.

% mkdir dotfiles
% cd dotfiles
% git init

After this we can continue by moving some of our dotfiles.

% mkdir vim
% mv ../.vimrc vim
% mkdir zsh
% mv ../.zshrc zsh
% git add -A
% git commit -m initial

Now we have moved some of our dotfiles to a new home and added them to git, but we still have to install some symlinks where these files are expected to be found.

% stow vim
% stow zsh

By running the previous commands we installed the symlinks automagically. We can even make stow remove them.

% stow -D zsh

To wrap things up. The great thing about this solution is how easy it is to use and one can even deside which dotfiles one want to have installed by splitting them up in separate subdirectories, or packages as stow calles it. I have been using this solution for some time now without any issues worth mention.

Mastodon