Managing home .dotfiles with git and GitHub

This is how I manage my user ~/ profile configuration files using GitHub.

Originally based on Silas Sewell’s description. It’s mainly here for my own reference and posterity, since we all know how widespread link rot is. (At the time of writing, the Pinboard.in blog is down due to unforeseen circumstances, reinforcing my point via circular meta-recursion.)

Features

  • Centralized configuration management
  • Files live in their native locations (no symbolic linking)
  • Home directory is not a git repo
  • All the power of git with a simple alias

First time setup

$ cd ~

$ mkdir .homeconfig.git

$ echo "alias homeconfig='git --git-dir=$HOME/.homeconfig.git/ --work-tree=$HOME'" >> .bashrc

$ source .bashrc

$ homeconfig init

$ homeconfig add .bash_profile .bashrc .bash_aliases

$ homeconfig commit -m 'Initial commit'

$ homeconfig remote add origin git@github.com:GITHUB_USERNAME/homeconfig.git

$ homeconfig push origin master

If you get an error when running config pull to the effect of “You asked me to pull without...” run the following:

$ echo -e '[branch "master"]\n remote = origin\n merge = refs/heads/master' >> ~/.homeconfig.git/config

Setup configuration on second machine

Add your public keys to GitHub (if you haven’t done so already).

$ cd ~

$ mv .bash_profile .bash_profile.bak

$ git clone git@github.com:GITHUB_USERNAME/homeconfig.git homeconfig.git

$ mv homeconfig.git/.git .homeconfig.git

$ shopt -s dotglob

$ mv -i homeconfig.git/* .

$ rmdir homeconfig.git

Logout and log back in. Enjoy!

Feel free to peruse my dotfiles at https://github.com/pithyless/homeconfig.

Suggestions or ideas on how to improve this setup? Leave a comment!

| Viewed
times