little cubes

You should version control your dot files

You know the ones, all those config files sitting in your home directory

Have you ever gotten a new computer, wiped your old one, and only then realized that the one thing you forgot to copy over was all the config files sitting in your home directory? Or maybe you made some config changes and later want to go back to the old version?

Wouldn’t it be nice if all your config files could be version controlled in the cloud? Capable of being copied down to any new computer in seconds?

Turns out, doing so is pretty simple!

The MethodSection titled: The Method

The idea is to create a new subdirectory of your home directory, move all the config files into that folder, and then use a tool called GNU Stow to symlink each of the config files back into your home directory.

  1. Create a new file in your home directory called dotfiles (or whatever you want to call it)

  2. Move all your config files into dotfiles, maintaining the same relative directory structure

    • Toggle the Before switch below for an interactive example
    $HOME
    dotfiles
    .gitignore
    Music
    .zshrc
    .aws
    credentials
  3. Install GNU Stow with the package manager for your OS.

    Terminal window
    brew install stow # Install on Mac via homebrew
  4. Invoke stow to create symlinks in your home directory

    Terminal window
    cd ~/dotfiles
    stow .
    • Now symlinks to all your config files should exist again in your home directory
    • Editing the symlinked files will also edit the files inside of dotfiles
  5. Create a private remote repository

    • Go to GitHub or GitLab or BitBucket or whatever remote repository provider you prefer and create a new private repo. Then copy the clone url for that repo.
  6. Create a git repository inside of dotfiles and push to your remote repo

    Terminal window
    cd ~/dotfiles
    git init
    git add .
    git commit -m "Initial commit"
    git remote add origin <your remote clone url -- i.e. https://repo.com/user/dotfiles.git>
    git push origin main

Now just edit your config files like normalSection titled: Now just edit your config files like normal

Boom, done! You can use and edit your config files like normal. Editing either file will update them both.

When you make changes to your config files, remember to commit and push those changes to your remote to back them up!

Add a README to your repoSection titled: Add a README to your repo

You can add a README.md file inside dotfiles to remind your future self how to use this repo.

It could look something like this:

# My dotfiles
This repo exists to help maintain home directory dotfiles between computers.
It is intended to be used with [GNU Stow](https://www.gnu.org/software/stow).
31 collapsed lines
## Requirements
Install [Stow](https://formulae.brew.sh/formula/stow) via homebrew:
```
brew install stow
```
## Installation
First, clone this repo in your `$HOME` directory using git:
```
cd ~
git clone https://github.com/0livare/dotfiles.git
```
then use GNU stow to create symlinks:
```
cd ~/dotfiles
stow .
```
The contents of `dotfiles` has now been replicated in your home directory, but with symlinks.
Because the files are symlinked, any changes to the files in the home directory will be reflected in the `dotfiles` directory, and vice versa. Changes to `dotfiles` can then be committed with git and pushed to the remote repository.
## More Information
For a more thorough explanation of this strategy, see [this blog post](http://olivare.net/blog/2024/version-control-dot-files).