Keeping dotfiles in sync

April 9, 2025

I wipe my systems, especially on Linux where data protability is much easier than on Windows or macOS, fairly regularly. For systems where I log in fairly regularly, such as my WSL sandbox or development server, I like to have my various dotfiles and scripts synced.

This also works for something like macOS. When I received a new workstation from work, I was able to get things up and going quite quickly even though I had opted to reconfigure everything from the beginning.

There isn’t really much of a need to use a specific dotfile manager. git is all you need.

Creating a dotfile store

Creating a dotfile store is as easy as creating a folder and create a bare Git repo inside of it.

mkdir ...
cd ...
git init --bare

The files created in this directory are usually put in the .git folder in most Git repositories. This folder will store all the Git data, while we treat our entire home folder as the “source code” of our project.

To take advantage of this, we’ll need to use Git with some arguments, the easiest way of going about it is creating an alias.

# ~/.bashrc

export DOTFILES_DIR="$HOME/src/itisrazza/dotfiles"
alias dfgit="git --git-dir=\"${DOTFILES_DIR}\" --work-tree=\"${HOME}\""

Adding files to the repo

You can now use the dfgit alias to add files from anywhere in your home folder as if you were in a git repo.

dfgit add ~/.bashrc
dfgit commit

Pusing and pulling changes

We’re going through the basic motions at this point.

# push the changes (for the first time)
dfgit remote add origin git@github.com:itisrazza/dotfiles.git
dfgit push --set-upstream origin "$(dfgit branch --show-current)"
dfgit push
dfgit pull

Cloning the changes to a new system

Setting these up on a new system is also quite easy. Once you set Git and your SSH keys up. You can simply clone the repository with the --bare argument.

git clone --bare git@github.com:itisrazza/dotfiles.git ~/src/itisrazza/dotfiles

Tips for dotfile management

Now that dotfiles are used across multiple systems, they may not offer the same commands and environments. Here are some tricks I use to make them easier to move about.

Split up your dotfiles