Tools are really important. They are the connection between the maker and what the maker is making. Craftsmen can spend a lifetime honing them just as they do their craft.
The configuration files on a computer with a
. in front of them—aptly named dotfiles—are my tools. Refined line by line, hour by hour, in pursuit of workflow nirvana.
When I first discovered dotfiles, I was immediately sold on the idea:
Backup, restore, and sync the prefs and settings for your toolbox. 1
The concept would allow me to bring my tools anywhere.
Zach Holman’s dotfiles seemed like a great place to start, but, despite their really nice organization, symbolic links and set up scripts introduced too much friction.
After further investigation, I found Kyle Fuller’s Organising dotfiles in a git repository and this nugget:
Git allows you to separate the work tree and the git dir via environment variables or arguments to the git command.
Separating the work tree and git directory make dotfiles “easily manageable via the git command,” which is what I wanted to do.
Onward to the tutorial!
First the code, then the explanation.
$ git init --bare $HOME/.dotfiles $ alias home="git --git-dir=$HOME/.dotfiles/ --work-tree=$HOME" $ home config --local status.showUntrackedFiles no $ echo "alias config='/usr/bin/git --git-dir=$HOME/.dotfiles/ --work-tree=$HOME'" >> $HOME/.zshrc
- Creates a new bare git repository in the
homeas the alias for
~/.dotfilesinstead of using
- Hides untracked files so
git statusoutput is manageable
Create versions with git
Now, just use
home instead of
$ home status A .gitconfig M .zshrc $ home add .gitconfig $ home commit -m "Add gitconfig" $ home add .zshrc $ home commit -m "Add zshrc" $ home push
I recommend pushing your local dotfiles repo to GitHub so you can clone it when you configure a new computer.
$ alias home="git --git-dir=$HOME/.dotfiles/ --work-tree=$HOME" $ home init .dotfiles $ home remote add origin https://github.com/tmm/dotfiles $ home fetch $ home checkout master
My dotfiles on GitHub.