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.
-
Create a new file in your home directory called
dotfiles
(or whatever you want to call it) -
Move all your config files into
dotfiles
, maintaining the same relative directory structure- Toggle the
switch below for an interactive exampleBefore
$HOME.gitignoreMusic.zshrc.awscredentials - Toggle the
-
Install GNU Stow with the package manager for your OS.
- On Mac you can install with Homebrew.
Terminal window brew install stow # Install on Mac via homebrew -
Invoke
stow
to create symlinks in your home directoryTerminal window cd ~/dotfilesstow .- 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
-
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.
-
Create a git repository inside of
dotfiles
and push to your remote repoTerminal window cd ~/dotfilesgit initgit 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 ~/dotfilesstow .```
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).