Is it a good idea to synchronize a Git project via Syncthing?

261 Views Asked by At

I am thinking about synchronizing a Git project via Syncthing but I assume this is a bad idea as there are hidden files.

Can you confirm this? Or will Syncthing do this correctly?

1

There are 1 best solutions below

0
On BEST ANSWER

In general, you should never synchronize a Git repository via any sort of continuous file synchronization utility, including Syncthing or any similar utility, such as Dropbox or iCloud. That's because Git writes data in a very particular order in order to preserve the integrity of the repository, and any sort of synchronization while the repository is not completely idle can corrupt it.

Any sort of continuous file syncing utility will sync as it sees operations happen, but it doesn't and can't guarantee that the operations will happen in the exact order that Git did them, which makes it impossible to preserve the required invariants.

If you do this anyway, the repository may end up corrupt, or you may see problems with duplicated files, files which end up reappearing after being deleted, or other hard-to-reason-about problems.

It is safe to use something like rsync as long as the repository is completely idle. That means that no Git processes are running, including git gc or any processes invoked by your editor or shell. Note that if you do this, due to the nature of the Git index, git status will have to re-read all of the files next time you sync.

It is also, of course, safe to use git push, git fetch, and git bundle at any time to transfer data.