Backing up dotfiles with stow
How to start using GNU Stow to make backups of your configuration files (dotfiles) and use git to version them and backup on a remote repo.
Setting up stow
Follow your package manager’s instructions for installing stow
if you don’t
have it installed already.
- Create a folder in your home directory. I’m naming mine
.dotfiles
and all examples here will use that naming. You can pick whatever you want. Change to that directory to continue the steps.mkdir ~/.dotfiles cd ~/.dotfiles
- Make folders in the
.dotfiles
directory for each app/tool you want to backup. For example: zsh, nvim, git…mkdir git mkdir zsh
- Move the config file from your home directory to the application folder you
created. Example for git:
mv ~/.gitconfig git
- Run the stow command to re-link the gitconfig file back to your home directory
stow git
- Verify the link:
> ls -l ~/.gitconfig lrwxr-xr-x 1 james staff 24 Mar 3 17:00 /Users/james/.gitconfig -> .dotfiles/git/.gitconfig
- Repeat the above 3 steps for all the items you want to stow
Setting up the git repo
Set up source control for your dotfiles to keep track of changes made and optionally make remote backups on git server.
I added this snippet to my .zshrc
to print a message when I sign in
that lets me know if there are pending changes to any of the files I’m
tracking in the .dotfiles
directory. (Tested with zsh)
if [[ `git -C ~/.dotfiles/ status --porcelain` ]]; then
echo "There's changes in .dotfiles!"
fi