I'm using GNU Stow to manage my dotfiles as per this guide. This works well for cases where there is no pre-existing dotfile on the machine. E.g. if there is no file ~/.config/foo.cfg then the following works well:
~/.dotfiles$ mkdir -p foo/.config
~/.dotfiles$ echo My config > foo/.config/foo.cfg
~/.dotfiles$ stow foo
~/.dotfiles$ ls -l ~/.config
lrwxrwxrwx 1 user group 21 Dec 6 19:03 ~/.config -> .dotfiles/foo/.config
It becomes less straightforward if ~/.config/foo.cfg already exists:
~/.dotfiles$ stow foo
WARNING! stowing bar would cause conflicts:
* existing target is neither a link nor a directory: foo.cfg
All operations aborted.
So far the only solution I can find is to manually delete ~/.config/foo.cfg and re-run stow foo. This is quite awkward when provisioning a stow repo to a new machine which might have dozens of pre-existing .dotfiles and essentially defeats the purpose of using stow to manage dotfiles.
Stow has the --adopt option. Running stow --adopt foo has the effect of replacing the stow'd foo files with the pre-existing foo files that are on the machine, and then creating the symlinks. What I'm looking for is the way to achieve the opposite; replace the machine's .dotfiles with a symlink to the stow'd version so that new machines can be provisioned using the stow'd dotfiles from a Git repo.
This seems like such an obvious requirement for using Stow to manage dotfiles that I feel I'm missing something and/or the problem has been solved.
Any ideas?