Commit ed1734fa05
Unsigned
Layout: unified · split
content/blog/2026-02-08-gnu-stow.org added +101
| @@ -0,0 +1,101 @@ | ||
| 1 | #+date: <2026-02-08 Sun 12:17:42> | |
| 2 | #+title: Managing My Dotfiles with GNU Stow and Git | |
| 3 | #+description: Learn how I use GNU Stow to manage my user dotfiles and configurations. | |
| 4 | #+slug: gnu-stow | |
| 5 | ||
| 6 | * What is GNU Stow? | |
| 7 | ||
| 8 | [[https://www.gnu.org/software/stow/][GNU Stow]] is described as a "symlink farm manager" on its homepage, which is | |
| 9 | true, but feels a bit underwhelming. Rather, I'd describe it as a tool to | |
| 10 | systematically and logically link, organize, and version control any files on | |
| 11 | your system. | |
| 12 | ||
| 13 | * Installation | |
| 14 | ||
| 15 | First things first: let's install Stow. I'm on macOS, so I run the following | |
| 16 | command: | |
| 17 | ||
| 18 | #+begin_src sh | |
| 19 | brew install stow | |
| 20 | #+end_src | |
| 21 | ||
| 22 | To ensure it's installed correctly, check the version: | |
| 23 | ||
| 24 | #+begin_src sh | |
| 25 | stow -V | |
| 26 | #+end_src | |
| 27 | ||
| 28 | * Stow Dotfiles | |
| 29 | ||
| 30 | Next, let's create a directory to use as the central source for all these files. | |
| 31 | In my case, I store all git repositories in my ~~/git/~ directory, so I will | |
| 32 | create a ~dotfiles~ directory here: | |
| 33 | ||
| 34 | #+begin_src sh | |
| 35 | # Create the dotfiles repository | |
| 36 | mkdir ~/git/dotfiles && cd ~/git/dotfiles | |
| 37 | #+end_src | |
| 38 | ||
| 39 | Next, let's stow our first set of dotfiles. We'll use ~zsh~ as an example here. To | |
| 40 | do this, we will: | |
| 41 | 1. Create a directory for Zsh. | |
| 42 | 2. Move our current Zsh configuration files into our Stow directory. | |
| 43 | 3. Use Stow to symlink the files back into our home directory. | |
| 44 | ||
| 45 | #+begin_src sh | |
| 46 | # Create the ZSH Stow directory | |
| 47 | mkdir zsh && \ | |
| 48 | # Move your ZSH files into Stow | |
| 49 | mv ~/.zshrc ~/git/dotfiles/zsh/ && \ | |
| 50 | mv ~/.zprofile ~/git/dotfiles/zsh/ && \ | |
| 51 | # Use Stow to symlink them back to your user home | |
| 52 | stow zsh | |
| 53 | #+end_src | |
| 54 | ||
| 55 | At this point, you have a centralized directory (~/git/dotfiles~) where you can | |
| 56 | stow any file and use ~stow~ to symlink it back to another directory on your | |
| 57 | system. | |
| 58 | ||
| 59 | Therefore, you only need to navigate to this directory to make changes across | |
| 60 | your system. | |
| 61 | ||
| 62 | * Update Dotfiles | |
| 63 | ||
| 64 | When you make changes to your Stow directory, you can inform Stow and have the | |
| 65 | program update its symlinks with the following command: | |
| 66 | ||
| 67 | #+begin_src sh | |
| 68 | cd ~/git/dotfiles && \ | |
| 69 | stow -R zsh | |
| 70 | #+end_src | |
| 71 | ||
| 72 | To summarize: | |
| 73 | ||
| 74 | | Action | Command | Why? | | |
| 75 | |---------------------------------+-------------------+--------------------------------------------------| | |
| 76 | | Edited a file | None (Just save) | The symlink already exists. | | |
| 77 | | Added a file to existing folder | stow -R <package> | To create the new symlink for that file. | | |
| 78 | | Deleted a file from dotfiles | stow -R <package> | To remove the "dead" symlink from your home dir. | | |
| 79 | | Created a whole new package | stow <package> | To link the new directory for the first time. | | |
| 80 | ||
| 81 | * Save to a Git Repository | |
| 82 | ||
| 83 | Lastly, let's finish the puzzle by ensuring that this configuration is | |
| 84 | long-lasting and can transfer amongst systems. | |
| 85 | ||
| 86 | To this end, we will use Git as our VCS. You can simply create the repository, | |
| 87 | add your files, and push to your remote. | |
| 88 | ||
| 89 | #+begin_src sh | |
| 90 | git init && \ | |
| 91 | git add . && \ | |
| 92 | git commit -m "initial commit" && \ | |
| 93 | git remote add origin GIT_URL && \ | |
| 94 | git push | |
| 95 | #+end_src | |
| 96 | ||
| 97 | If you want to automate this even more, write an alias or a hook into your ~stow~ | |
| 98 | command to automatically commit your changes whenever they occur. | |
| 99 | ||
| 100 | At this point, I have organized and managed my dotfiles much more efficiently | |
| 101 | and no longer lose them whenever I wipe my machines. | |