Putting My Home Into Git

Tue 28 August 2018 by pj Tagged as linux

So I currently have two laptops: one for work and one for personal use. There is, however, a fair bit of overlap; I'd like to have a bunch of config files (.bashrc, .vimrc, ~/.config/i3/config, etc) and a bunch of useful scripts (in ~/bin) available in both places. I looked at a couple solutions, including dotfiles and such, but a post on StackOverflow had the outline of a solution that I'm fairly happy with.

I put an alias into my .bashrc:

  • alias homegit='git --work-tree=$HOME --git-dir=$HOME/.home.git'

And wrote a little script to automate setup on new machines:

#!/bin/bash

if [ -d "$HOME/.home.git" ]; then
   echo "homegit already set up."
   exit 1
fi

homegit="git --work-tree=$HOME --git-dir=$HOME/.home.git"

$homegit init
$homegit remote add origin $MY_HOMEDIR_REPO
$homegit fetch origin
$homegit reset
$homegit checkout -t origin/master

and then ran it. Then I wrote an info/exclude file:

# exclude everything
/*
# ...except the following
!/bin

!/.home.git/info
!/.xscreensaver
!/.git_template
!/.gitconfig
!/.screenrc
!/.bashrc
!/.vimrc
!/.xinitrc

!/.config
/.config/*
!/.config/i3/

So only the files I wanted to save were listed in a 'homegit status'. Then I could just homegit add them and could go to town!

I imagine maintaining the info/exclude file is going to be the main issue, but it's probably good for me to keep up with that minor skill anyway.