2 min read
Managing dotfiles

How to manage your dotfiles using GNU Stow

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:

  1. First, install GNU Stow:

    # On macOS
    brew install stow
    
    # On Debian
    sudo apt-get install stow
    
    # On Arch Linux
    sudo pacman -S stow
  2. Create a dotfiles directory:

    mkdir ~/.dotfiles
    cd ~/.dotfiles
  3. Organize your dotfiles into packages. For example:

    .dotfiles/
    ├── zsh/
    │   └── .zshrc
    ├── vim/
    │   └── .vimrc
    └── git/
        └── .gitconfig
  4. 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

  1. Version Control: Initialize your dotfiles directory as a git repository:

    cd ~/.dotfiles
    git init
    git add .
    git commit -m "initial dotfiles setup"
  2. Unstowing: If you need to remove symlinks, use:

    stow -D package_name
  3. Restowing: To update symlinks after making changes:

    stow -R package_name
  4. Existing Files: If you have existing dotfiles, back them up before stowing:

    mv ~/.zshrc ~/.zshrc.backup