Can syncthing reliably sync local Git repos? (Not Github)

I thought about using Syncthing to sync git repos to other local servers as an easier alternative to setting up a git server on another development box in my network. Trying to use a remote repo on a remote server (local network, not Github) has been shown not to work properly and is not an advised setup, due to the fact that the repo will eventually become corrupted. The proper way to do this is to set up a git server on an another machine, which does take a lot of work due to a learning curve. I recently discovered Syncthing and I was wondering if it could be used to reliably backup a git repo without corrupting it, as a quick alternative to setting up a Git server. Thanks.

1 Like

You said it yourself…

You should host something like Gogs, Gitolite or Gitlab.

2 Likes

I expect that your repo will become corrupted almost immediately.

Syncthing doesn’t understand anything about how Git wants to use its internal metadata, and will naively sync all the various files between nodes.

So, if one node is on branch A and the other on branch B, both the work tree and the Git metadata files will be totally messed up once Syncthing “syncs” them.

Depending on your use case, a simple SSH server may be enough for your Git needs.

2 Likes

You could also create a “push-only” setup. Where you have “central” syncthing instance and send your changes in master folder from the client.

1 Like

In that case, it’s probably a good idea to ignore the ‘.git/’ metadata. Because the leaf nodes of the cluster will see themselves as the central node and it will not be that useful.

1 Like

There can still be issues. They’re rare, but they occur when you put a git repository into any sort of synchronized folder (Dropbox, etc). Lots of small files changing often tend to confuse file synchronization tools a bit, and you end up with repository corruption sooner or later. It’s rare, but it’s common enough that we tell people never to do this with git.

Why not just use git as it’s intended to be used? If you can set up Syncthing and let it through your firewalls, NAT, etc, you can set up a local git server.

The answer to the topic question “Can syncthing reliably sync local Git repos?” is definitely no.

You can sync git repos some of the time under certain circumstances, if you take good care and understand the underlying mechanics of the repo. But that’s not “reliably”, and you’re quite likely to corrupt your repos at any time by a simple handling mistake that Syncthing will gladly let you do.

In other words, if you need to ask this question the answer is no.

If you fully understand the git on disk format you can of course do what you like, including using normal rename and link to create branches, etc… But then you’re not in here looking for advice on the topic.

4 Likes

I think you misunderstood my intention about this question (probably my fault!). Of course I wouldn’t expect to be able to do development on more than 1 machine at the same time. I was purely speculating that you could use Syncthing as a rudimentary backup for a git repo from a master (ie your main dev box) to a slave (backup device). But, if my master box dies for some reason, would I be able to continue development on the slave box (which would probably become the new master). I suppose this would not work if some of the meta data is host specific, but I don’t know too much about the git meta data.

1 Like

Hi Stefan, thanks for your response, but you have entirely missed the point of my question. I am not intersted in merging work from other developers. I am not interested in any complex features, or doing simulataneous development on multiple machines. The intention behind this question was for a very rudimentary backup to be used in the short term before setting up a fully blown server as others have suggested.

1 Like

Ah, now that sounds like a solution I could use :slight_smile:

Sounds like like good advice. But actually, that would mean no git history would be backed up too? I think I’ll abandon this whole train of thought and just install a git server. Cheers anyways.

Okay, I think that using Syncthing for this could work in some specific and limited Git use cases. But, if you can set up Syncthing, it’s probably possible to also use SSH, which will allow you to use Git fully.

It seems you just need a backup solution, yet Syncthings main goals are not backups.

2 Likes

For backups use borg:

1 Like

Borgbackup works very well, it is stable and works on many platforms! I highly recommend this. I use it to backup ~10 servers every night. I have written the deployment example (using one ssh key per server to lock into a backup archive). https://borgbackup.readthedocs.io/en/stable/deployment.html

1 Like

As I said, borg is much better suited for backups. Syncthing is intended to keep files available on several devices.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.