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

Nguyen EngineerNguyen Engineer
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.

10
Subscribe to my newsletter

Read articles from Nguyen Engineer directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Nguyen Engineer
Nguyen Engineer

👋 Hi, I’m Nguyen, or you can call me Finn 💾 Vimmer ❤️ Gopher 📍I'm based in Da nang, Vietnam ⚙️ I love working with Go and Typescript ⚙️ I love both building distributed systems and the artistry of creating a single binary that efficiently uses minimal resources to accomplish as much as possible.