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.
You said it yourselfâŚ
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.
You could also create a âpush-onlyâ setup. Where you have âcentralâ syncthing instance and send your changes in master folder
from the client.
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.
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.
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.
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.
Ah, now that sounds like a solution I could use
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.
For backups use borg:
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
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.