Manage your dotfiles with chezmoi

Managing configuration across multiple machines can get frustrating and tedious. Be it working on more than just one computer or setting up a new machine can cause some serious work till being productive.

For that exact reason, roughly half a year ago, I was looking for a convenient way to manage dotfiles aka the configuration and sync between my MacBook and the Hack Rig that I mostly enjoy working on from home. Doing some websearch I was running into chezmoi.

And it does exactly what I was looking for!

Chezmoi keeps a shadow of everything I want it to keep track of. And this shadow directory is backed by git version control.

Getting started was super easy and straight forward! These roughly are the steps it took for me.

$ brew install chezmoi

I am using homebrew as a package manager and prefer not to directly run a curl output in my shell - maybe except for installing homebrew itself 😅. How to install without a package manager can be found on the chezmoi homepage or other package managers for other systems on their installation overview.

And that's it - you're now able to start adding files you want to be managed by chezmoi like so:

$ chezmoi init
$ chezmoi add ~/.zshrc

You then can very easily wire it up with a remote repository:

$ chezmoi cd
$ git remote add origin https://github.com/$GITHUB_USERNAME/dotfiles.git
$ git add .
$ git commit -m "Dotfile update"
$ git push

And on another machine - it's as simple as

$ chezmoi init https://github.com/$GITHUB_USERNAME/dotfiles.git
$ chezmoi apply

On any machine that already is initialized you can simply run the following to pull and apply the latest changes.

$ chezmoi update

There is so much more - apart from proper tooling around diffs for staged changes, and handling merges, even one time scripts that can be used to handle brewfiles. If this article hooked up your interest - go check out the chezmoi quick start.

Chezmoi already saved me a ton of time in my work life syncing my neovim config back and forth, adding new packages and configs, etc. And soon there will be a new MacBook welcomed to my fleet - I know I will be up and running in no time 🚀.

Oh ... and you can check out my own dotfiles over at GitHub 🤠.

And ... that's pretty obvious - still putting it here as it's important - ☝️ do not put secrets in files you upload to a remote!

Cheers - 🍺