Sync directories containing git repository with unison

前端 未结 2 1096
一整个雨季
一整个雨季 2021-02-15 17:04

I want to sync a directory containing a git repo of my dotfiles on two machines. Both machines will make changes to the files in the repo. Normally I use unison for syncing dire

2条回答
  •  自闭症患者
    2021-02-15 17:37

    Based on VonC's advise, I'm going to relax the requirement of live syncing the entire git state and simply ignore the .git directory with unison and just use git fetch.

    Relevant part of my .unison/dotfiles.prf:

    root = /home/khouli/dotfiles
    root = ssh://other_machine//home/khouli/dotfiles
    ignore = BelowPath .git
    

    Note that BelowPath matches exactly the path .git. So depending on the project structure ignore = Name .git may be better suited. More details on pathing in Unison here.

    Relevant part of my sync script:

    unison dotfiles
    (cd $HOME/dotfiles && git fetch)
    ssh other_machine 'cd dotfiles && git fetch'
    

    This syncs the files themselves and the commit history. It doesn't sync staging but that's not too important and it might not even be desirable. This also requires that both machines have an appropriate network connection for a git fetch. Otherwise git bundle like VonC suggests could be used.

    This is just here incase anyone comes here from google and finds it useful. I'm not marking it as accepted because it'd be interesting if an answer showed up with a way to live sync a git repo.

提交回复
热议问题