Ideal Dotfiles Storage

Dotfiles (or hidden files because ls doesn’t show them by default), so called because they often begin with a . on *nix systems, are where user configuration for applications are usually located. Examples include ~/.vim, ~/.config, and ~/.bashrc.

Over the years, I’ve tried many different methods for storing my dotfiles, from storing dotfiles in a subdirectory and symlinking, to rsync and GNU stow. But the most elegant method I found was detailed in this Hacker News comment. Instead of fiddling around with external dependencies or symlinking (which can be quite dangerous if one does a recursive link by accident, as I did once), this method uses a git bare repository in a subdirectory of $HOME to track dotfiles.

First, we’ll create a git bare repository, and create an alias config for the long git command describing the bare repo.

git init --bare $HOME/.cfg
alias config='/usr/bin/git --git-dir=$HOME/.cfg/ --work-tree=$HOME'
config config --local status.showUntrackedFiles no

# bash users
echo "alias config='/usr/bin/git --git-dir=$HOME/.cfg/ --work-tree=$HOME'" >> $HOME/.bashrc
# zsh users
echo "alias config='/usr/bin/git --git-dir=$HOME/.cfg/ --work-tree=$HOME'" >> $HOME/.zshrc

Govind Gnanakumar image
Govind Gnanakumar

Hunting Flutter devs through the multiverse