4

Is anyone using Unison (http://www.cis.upenn.edu/~bcpierce/unison/) to keep development projects consistent between laptop and desktop or similar?

I'm worried Unison may butcher my git repos. Given MyProject, with the laptop checked out on somebranch and the desktop checked out on someotherbranch, will Unison do the right thing on a sync? I don't care which branch wins, so long as the repos stay viable.

Other suggestions welcome. Rsync is a fallback if nothing else works.

Brian
  • 8,791
  • 3
  • 15
  • 9

2 Answers2

2

Yes, I use Unison regularly to sync all of my projects, including bzr and git repos. It works fine. The result is the same as pushing your git repo somewhere and then pulling it again from there, but if you're already using Unison, it eliminates those extra steps if you just sync the repositories. Syncing also picks up your uncommitted changes, which a push + pull won't do.

The only problem I can see happening is if your Unison profile has some ignores set that keep you from syncing all of the objects in the git repo. I think that would be unusual though, and it's never happened to me.

Andrew Schulman
  • 3,395
  • 1
  • 21
  • 23
  • 1
    I think you need to reconsider this. What happens if you've modified some files on both sides, and you've done `git add A` on one side and `git add B` on the other side, but you haven't done `git commit` on either. Only one version of the `index` will win - Unison doesn't merge changes without extra work - so you will lose state... Or if you've made 3 commits on one repo, and 4 commits on the other - one set of those commits is going to get lost, or you're going to get a corrupted repo depending on how you answer Unison's conflict resolution questions... – twalberg Dec 17 '14 at 20:16
  • Yes, that's possible, but it's no different from other sync conflicts that you have to resolve. If Unison finds a file (the git index) that's changed on both hosts, it will ask you what to do. If it seems to be mixing changes from both sides, you can always force it to copy one way or the other. And a git push + pull won't handle that case either. – Andrew Schulman Dec 17 '14 at 20:19
  • 1
    But a `git push` or `git pull` will at least refuse to operate in certain situations that are dangerous, and give you hints on what you need to do to resolve the situation. Even if you're being a good `git` citizen and working on different branches in your two different repos, Unison is going to either stomp all over one set of work or try to do some sort of mix and match that `git` isn't going to like, depending on what input you give it. Of course, if you're disciplined enough to never work in both repos, you might get away with it... – twalberg Dec 17 '14 at 20:30
  • It's never happened to me, but even if it did, the impact is minor - a `git reset` would fix it. But more generally, this problem is true of any work you synchronize between hosts. If you work in both places and then sync, you may have to manually resolve a conflict. That's usually not fun, so after a while you learn to always resync before you start work. – Andrew Schulman Dec 17 '14 at 20:48
  • Do you manually switch to the same branch on both the machines before syncing using unison? – elexhobby Apr 01 '21 at 18:58
  • I don't think this has ever come up for me, but yes, that would seem to be a good idea. – Andrew Schulman Apr 01 '21 at 19:57
0

I'm using Unison as well and it is working fine for me. The only real problem I had was related to case sensitivity. I installed Unison on my Linux machine and on my MacOSX for synchronizing files between the two. MacOSX by default uses a case-insensitive file-system, so I had some conflicts. The workaround was to create a read-write disk image using Disk Utility and use this newly created volume as my base working directory for working with git-repos.

Davide Ungari
  • 1,920
  • 1
  • 13
  • 24