Finally, I found the best way to keep dot files in sync

Photo by Jesse Bauer on Unsplash

Finally, I found the best way to keep dot files in sync

·

1 min read

I was struggling to keep my dotfiles in GitHub in sync with the dot files in the $HOME directory. But now it is so smooth.

Cut to the chase, here is what I do:

  1. The $HOME folder will be the single source of truth. I keep all the original files here

  2. Use rsync to sync all the files from $HOME to dotfiles Github local repo

  3. Commit the files to the origin to backup.

You may have many files so you may have many rsync commands, let pack it into a bash function and add it to your ~/.zshrc

dotsync() {
  rsync -r ~/.config/nvim/* ~/projects/dotfiles/nvim
  rsync -r ~/.config/karabiner/* ~/projects/dotfiles/karabiner
  rsync -r ~/.config/kitty/* ~/projects/dotfiles/kitty
}

My dotfiles repo is public here https://github.com/finnng/dotfiles

There are a lot of benefits to this approach

  1. My dotfiles repo is pristine since the file itself is the single source of truth

  2. No more linking issues like sometimes you have to force linking with ln -fs

  3. Stress-free, no more file conflict, let the rsync command deal with it.