About
From the ArchWiki:
User-specific application configuration is traditionally stored in so called dotfiles (files whose filename starts with a dot). It is common practice to track dotfiles with a version control system such as Git to keep track of changes and synchronize dotfiles across various hosts. There are various approaches to managing dotfiles (e.g. directly tracking dotfiles in the home directory v.s. storing them in a subdirectory and symlinking/copying/generating files with a shell script or a dedicated tool).
GNU Stow
The tool we are going to use to manage our dotfiles is GNU Stow. Here is a step-by-step guide to get started with Stow:
-
First, install GNU Stow:
# On macOS brew install stow # On Debian sudo apt-get install stow # On Arch Linux sudo pacman -S stow
-
Create a dotfiles directory:
mkdir ~/.dotfiles cd ~/.dotfiles
-
Organize your dotfiles into packages. For example:
.dotfiles/ ├── zsh/ │ └── .zshrc ├── vim/ │ └── .vimrc └── git/ └── .gitconfig
-
Use Stow to create symlinks:
cd ~/.dotfiles stow zsh # Creates symlink for .zshrc stow vim # Creates symlink for .vimrc stow git # Creates symlink for .gitconfig
Best practices
-
Version Control: Initialize your dotfiles directory as a git repository:
cd ~/.dotfiles git init git add . git commit -m "initial dotfiles setup"
-
Unstowing: If you need to remove symlinks, use:
stow -D package_name
-
Restowing: To update symlinks after making changes:
stow -R package_name
-
Existing Files: If you have existing dotfiles, back them up before stowing:
mv ~/.zshrc ~/.zshrc.backup