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!

20 comments

  1. [5]
    JoshuaJ
    Link
    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...

    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.

    14 votes
    1. ewintr
      Link Parent
      An easier way is to create a simlink to the file in the repository: Backup your current .bashrc, remove it and do: $ ln -s ~/dotfiles/bash/bashrc ~/.bashrc (Update paths to your specific...

      An easier way is to create a simlink to the file in the repository:

      Backup your current .bashrc, remove it and do:

      $ ln -s ~/dotfiles/bash/bashrc ~/.bashrc
      

      (Update paths to your specific situation, obviously)

      5 votes
    2. kaffo
      Link Parent
      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...

      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!

      1 vote
    3. [2]
      first-must-burn
      Link Parent
      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...

      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.

      1 vote
      1. JoshuaJ
        Link Parent
        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.

        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.

        2 votes
  2. [3]
    fxgn
    Link
    If all of your dotfiles are in ~/.config, you can just use a plain git repo. Otherwise, consider using a dotfiles manager like chezmoi.

    If all of your dotfiles are in ~/.config, you can just use a plain git repo. Otherwise, consider using a dotfiles manager like chezmoi.

    9 votes
    1. shrike
      Link Parent
      +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...

      +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

      3 votes
    2. tauon
      Link Parent
      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...

      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.

      2 votes
  3. [2]
    goose
    Link
    Two options I can think of: Any time I launch a shell, it uses 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...

    Two options I can think of:

    1. Any time I launch a shell, it uses 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 use rsync 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 with vim.
    2. Use a daemon like SyncThing to watch/sync those files between hosts. Advantage is that it doesn't require a single "main host" to be online, it's decentralized and more resilient to offline changes. But an extra daemon.
    5 votes
    1. infpossibilityspace
      Link Parent
      +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...

      +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.

      1 vote
  4. Macha
    Link
    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'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.

    3 votes
  5. carrotflowerr
    Link
    I cant speak for it myself but I know a lot of people use GNU Stow

    I cant speak for it myself but I know a lot of people use GNU Stow

    3 votes
  6. hungariantoast
    Link
    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...

    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.

    2 votes
  7. borntyping
    Link
    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...

    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.

    2 votes
  8. pete_the_paper_boat
    Link
    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.

    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.

    1 vote
  9. zonk
    Link
    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...

    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

    1 vote
  10. xk3
    (edited )
    Link
    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...

    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:

    ssh PC -t tmux new-session -A -s phone "'fish -c clean_home; exec fish'"
    
  11. akselmo
    Link
    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...

    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

  12. knocklessmonster
    Link
    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

    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