Version your dotfiles
I ran into Gary Bernhardt’s dotfiles1 for the first time around 2015, a few years into my career. His 500 line vimrc and intricate git helpers (which I immediately copied) freaked me out. I thought: wow, I could never make anything like that. How could someone put all this together?
It turns out all you have to do is spend 1,000+ hours programming every year for 10 years. Ok, not really. All you really have to do is put your dotfiles in a git repo. If you make your dotfiles a formal codebase, you will treat them like a codebase: you’ll cultivate and incrementally improve them over time — possibly a very long time. Copy from others, add an alias or a script when an idea strikes you in the moment. Eventually you’ll end up with a nice set of personal tools and tricks.
How I do it
My repo lives in ~/repos/dotfiles. There’s a bash script
install.sh
in there that symlinks2 a hard-coded list of files into the home dir. That’s
the whole thing. When I want to change something, I edit the
relevant file and make a commit. If I add a new
config file, like when I added a global .gitignore, I add it to install.sh and run the script.3
How to get started
- Make a git repo
- Copy a dotfile into it, like
.gitconfig - Create
install.shin the repo.
This will replace the original file with a symlink to the one in your repo.#! /usr/bin/env bash ln -sf "$PWD/.gitconfig" "~/.gitconfig" chmod +x install.shto make it executable- Run it with
./install.sh.
Not all config files live in the home directory. VS Code keeps its config
somewhere else.4 That’s fine: you can create vscode/settings.json
in your repo and symlink it wherever it belongs.
There are lots of tools around like stow or chezmoi for managing the symlinks, but a short bash script is all you need. It’s better to start with a minimal setup you can fully understand and only use fancier tools when you have a reason to.
Put it on GitHub!
This is optional but recommended. It’s great to be able to send someone a GitHub link to show how you did something. Be careful not to push anything secret, like API keys.
Footnotes
-
In Unix OSs, dotfiles are those config files and directories like
.gitconfig,.vimrc,.zprofilein your home directory that start with.to make them hidden. Many apps now put their config files inside~/.config/to reduce clutter. Other config files may not start with a dot, but they’re often called dotfiles anyway. ↩ -
I can run
install.shover and over because symlinking the same files again doesn’t do anything. ↩ -
https://code.visualstudio.com/docs/editor/settings#_settings-file-locations ↩