Tuesday, March 15, 2011

Version controlling my home directory

I recently rearranged my home directories on my work machines and decided it was time to finally get my configuration under a proper version control. I found several blogs about this, but one was particularly useful. I've changed it a little, but here's the basic set up.
$ mkdir ~/.config.git
$ cd ~/.config.git
$ git init --bare
$ git config core.worktree ../
Now I have a git repository called ~/.config.git, but it needs special environment variables set so that accidentally calling git outside a normal repository won't trigger it to do things to my config repo. The next step is to make it easier to use this repo. I wrote the following to ~/bin/git-home:
export GIT_DIR=$HOME/.config.git
git "$@"
Now calling "git home ..." explicitly sets the repository to my config repo. But this still isn't so convenient. So I added the following to my (now version-controlled) .bashrc file, at a point after completions are loaded:
alias hgit='git home'
complete -o bashdefault -o default -o nospace -F _git hgit 2>/dev/null \
|| complete -o default -o nospace -F _git hgit
This sets up hgit with completions. Finally, I don't want hgit status to show tons of untracked files. So I added the following ~/.config.git/info/exclude:
Beneath that is a list of specific exclusions, which I'll keep expanding as I discover files and directories I don't want to track.

No comments: