12
votes
How do I sync my dotfiles between PC and laptop?
I've been struggling with this for a long time. I want to keep my workflow consistent independent of my "workstation", and have identical dotfiles (like .bashrc, .vimrc etc.) on different devices.
So... How you personally deal with this issue, and what should I do?
Thanks!
I simply put them in GitHub, a private repo if you don’t want others to see.
Then you can do git clone and mv or just copy and paste the raw text from the GitHub website into the files.
I’ve maintained zsh, vim, emacs like this for many years.
An easier way is to create a simlink to the file in the repository:
Backup your current
.bashrc
, remove it and do:(Update paths to your specific situation, obviously)
I used to use Dropbox until I got sick of it (and the Linux client was always a pain in the ass). Now I use a git repo too.
But I always torture myself by pulling the repo with a raw, un-aliased pull first. Always reminds me how good configuration is on a new machine!
I add to this a script that goes and inserts an include / source instruction in the local .bashrc (or whichever file) to incorporate the file from the git repo while leaving it in the repo.
I am not at my PC right now, but the heart of the bash script is an "insert this line in this file if it is not already present" function. Probably a
grep -c
test to condition the insert.Like @macha said, symlinking out of your git repo is also an option, but I like that I get my "standard" stuff everywhere, but can make local tweaks as needed outside the git repo. If it's not a local tweak, I make it in the git repo, that way I can commit it back and sync / save it for posterity, and I avoid the copy/paste requirement.
I just don’t do it often enough that it’s worth automating. I set it once and then don’t touch it again for like 3 years.
If all of your dotfiles are in ~/.config, you can just use a plain git repo. Otherwise, consider using a dotfiles manager like chezmoi.
+1 for chezmoi
I’ve used multiple different systems during about 2 decades and chezmoi is the first one that just works and doesn’t try to be too much.
Plus it’s super easy to bootstrap on a new machine
In addition to the previous praise, I’d like to note that even if you’re already storing everything in
~/.config
(meaning a single git repo “could” be enough theoretically), and there are no differences from machine to machine, chezmoi can insert secrets such as API keys from password managers’ CLI tools. This means you can actually make your dotfiles repo hosted and public, able to be cloned and set up without any access tokens, only the (hopefully remembered by heart) password manager’s credentials required.I haven’t actually needed it yet, but I like to imagine I could get to work on any modern unix-y machine and feel comfortably “at ~” relatively quickly, provided it has internet access and a shell I can work with.
To me this is kind of reminiscent of the losing all your stuff in a house fire thought experiment – having a config/setup repo also seems like good practice for keeping a “backup” of sorts that’s both off-site and always current, and gets all the more relevant the more time you spend in front of a computer.
Two options I can think of:
rsync
to pull my dotfiles from my "main host", a VPS I rent. Then I have some hooks in my.vimrc
that when I edit those files and save them, they hooks usersync
to automatically push those updated files to my "main host". Works well, as long as I'm only editing those files when I have a good connection, and I only edit those files withvim
.+1 for rsync, assuming both machines can be on at the same time.
From the sounds of it, you don't need the change history which git gives you, plus it's another thing to remember to add to your repo which you might not want.
Rsync is one of the rare tools that always just works.
I've been slowly migrating more to home-manager and nix but my old solution was to have a dotfiles repo and a shell script to symlink/mkdir as appropriate.
I cant speak for it myself but I know a lot of people use GNU Stow
I actually wrote an article a while back about how exactly I use GNU stow: https://gabevenberg.com/posts/dotfile-management/
I use a git bare repo:
https://www.atlassian.com/git/tutorials/dotfiles
https://www.ackama.com/articles/the-best-way-to-store-your-dotfiles-a-bare-git-repository-explained/
I prefer this approach because it’s simple and reinforces your understanding of git’s basics. It doesn’t require special software. Any Linux distribution will have git available as a package and documentation on how to install it.
You can maintain separate branches for each device, if you want. I personally don’t. All my configs are hostname agnostic, so I just keep everything synced in one branch.
This setup also integrates well with git-annex, if you want to go the extra mile and sync not just your dotfiles, but all of your files across any number of computers.
I use Ansible to provision dotfiles onto all my machines. It's a bit overkill, but has some nice advantages like being able to install the programs that use the dotfiles and configuring machines differently in the rare case I need that.
Git is the way to go. You get a nice history and branching as a bonus. In case you ever need to make quick ugly changes that you want to incorporate cleanly in the future.
Maybe (depending on the kind of project) you can set up a remote ssh coding session [1] and connect from both workstations to it? Granted, this option has several caveats but it is an option nonetheless :)
[1] https://code.visualstudio.com/docs/remote/ssh
You can use both Git and Syncthing concurrently. I guess my main reason for using both is that I've been adding my home folder to Git very slowly over time--one file or folder per day. But Syncthing is also good at syncing things that I don't want in Git. Syncthing is not so good at resolving file sync conflicts, merging line-specific changes but Git is good at that.
They have different ignorefiles. I don't sync my whole home folder in syncthing, only
.local
and.config
:I symlink ./.stignore so that syncthing will also sync the ignore files
https://github.com/chapmanjacobd/computer/blob/main/.config/.stignored
I run this script every time I switch computers: clean_home usually via:
Put them in private git repo, link the files from the repo to their places, so every time you modify the file its changed in the repo too.
Then do this on all machines and when you want to update your dotfiles, you just git pull
If you want local sync use git to manage versioning and then Syncthing maybe?
I just anonymized my stuff, usually, and slapped it into a public GitHub in case anybody finds it useful