jdispan.de

Versioning and syncing Linux config files

We want to keep our config files organised and synced over multiple devices. We don't want to have our entire home directory as a git repository, because that would interfere with git repositories inside the home directory (e.g. in ~/git/).
We solve this by creating a git repository in some subdirectory of $HOME and defining aliases that let us conveniently work on it with the work tree set to $HOME.

Prerequisites

Initialisation

  1. Navigate to your home directory.
  2. Run git init --bare dotfiles
  3. Add alias config='/usr/bin/git --git-dir=$HOME/dotfiles/ --work-tree=$HOME' to your .bashrc
  4. Restart your shell
  5. Run config config --local status.showUntrackedFiles no
  6. If you want syncing, run
    config remote add origin git@github.com:someuser/somerepo.git and then
    config push -u origin master. Replace the URL in the first command with one pointing to your own remote repository.

Versioning and syncing

You can now use your home directory like an ordinary git repository. This works by using the alias config, which we defined in the previous step. For example, we can version our .bashrc like this:
  1. $ config add .bashrc
  2. $ config commit -m "Versioned .bashrc"
  3. $ config push

Original source

This video.