0

I am looking for a solution that will allow me to keep a Git repository in sync between my two workstations and my Android smartphone. My workstations turn on and off on a regular basis, and they are almost never on at the same time. My Android device is online almost always, but the network gateway it is connected to changes often. I have a local Git repository on my two workstations that I currently sync manually by bringing both systems online, copying the repo to Dropbox, downloading from Dropbox on the other workstation, and then doing a Git merge. I want to cut Dropbox out of my digital life (due to privacy concerns). I considered substituting Syncthing into this workflow, but after reading countless posts on their form about how Syncthing destroys Git repos, I decided against it.

I am looking for a tool that I can run upon shutdown of my Linux system (both of my workstations run Linux) that will push my local Git repository to either my Android device or my other workstation (I will choose the one that is online at the time) without using a central server. My repository contains sensitive information, so using Github as a middle-man is not an option (and this is also why I am trying to get the repo off Dropbox). I know there are paid private Git hosting services out there that implement full-encryption, but I would rather stick to something free.

In summary, I need a Git synchronization solution that...

  • Is free and P2P
  • Establishes a connection automatically (like Syncthing, where other nodes are discovered and securely connected to without having to tinker with firewalls or router settings)
  • Encrypts data over the network
  • Resists repository corruption

Note: I do not need the repository to be in sync in real-time between all three devices. I just want to make sure that when I shut one of my workstations down, it first makes a push to another one of my online devices. This way, my latest commits do not become unaccessible while that workstation is offline. (I have a shutdown script that I use to power off my workstation, so I will integrate this push command somewhere in there.)

8
  • 2
    Would a self-hosted "server" be an option? I use a very light-weight one here that even runs fine on a Pi, so it's very resource friendly, and gives you almost the flexibility sites like Github/Gitlab offer without involving 3rd parties: Gitea. Easy install on Linux, just a single binary to download/update.
    – Izzy
    Mar 2, 2021 at 2:03
  • @Izzy I would like to setup a server such as a PI. However, at this time, I feel that I do not know enough about network security to do it in a proper manner. I would be concerned that by opening up my router that an intruder would be able to take over the Pi and thus gain access or quietly steal data from other devices on the network. Something like Syncthing is nice for me because I trust that they know how to ensure the connection between my various devices is reasonably secure (something I do not know how to do).
    – DanielTA
    Mar 22, 2021 at 0:05
  • 1
    Well, if you want to sync a git repo, you should do that with git. As for your security concerns: Gitea would run locally on your Pi. No need to open any ports. You'd then leave the Pi permanently on (mine only uses 2.5W with an SSD attached), and your other devices to a git push|pull whenever they come online and connect to your local network. If it needs to be done from "outside", only use SSH and only allow key-based auth. Nothing is 100% safe or secure, but this would be pretty close.
    – Izzy
    Mar 22, 2021 at 1:27
  • @Izz This sound like a good setup. How might I deal with my public IP address changing though?
    – DanielTA
    Mar 23, 2021 at 0:00
  • 1
    Use a dynamic DNS service for that. There are several out there. I don't know which ones are currently recommended, though (I'm using my own, as I run my own primary DNS for my domains). Some are mentioned here at Wikipedia. Those services assign you a host name in their domain, and a client on your machine "pings" their servers to keep the record updated.
    – Izzy
    Mar 23, 2021 at 2:26

1 Answer 1

1

Gitea should meet your needs:

  • Is free and P2P: It's free & open source (you can find it at Github). While not P2P, as we found out that part can be solved by other means.
  • Establishes a connection automatically: This part could be covered configuring "mirrors" – but that would not really meet your needs. Using e.g. a simple Raspberry Pi as your "Gitea server", you could configure your other machines to do a git push/git pull whenever they connect to a network. Or do it by scheduled intervals: if there's no network, the job will fail – but it will succeed on a subsequent run when it's available.
  • Encrypts data over the network: Sure. Set it up via SSH, and use git:// URLs.
  • Resists repository corruption: as this way you work with git's own commands, your "master copy" (the one stored with Gitea) should be pretty stable. If you have uncommitted changes in your local repos when performing your "automated pulls", that's a different thing – which is why I would not recommend "automated syncs" anyway (they might hit you in the midst of your work). Running the proper push/pull commands is easily triggered manually.

Apart from these listed requirements, let me address your other two questions:

Configuring Gitea to only accept requests via SSH – and only via SSH keys at that, the risk of forwarding a port via your router for access from "outside" is rather minimal: an attacker would need your private keys to get in. Just keep all other ports closed (e.g. the one to Gitea's Web Interface – which you can use from inside your local network for all other work, like wiki articles or issues).

Now with your IP address being subject to change: than can easily be covered by a so-called DDNS service, which will assign you a hostname to use – while a client on your Pi or even inside your router (AVM's Fritz!Box'es have it even integrated by default) takes care to tell the service which IP it should direct that hostname to. Some such DDBS services are mentioned here at Wikipedia.


I'm using Gitea for years on a small BananaPi. The little box consumes about 2.5W with a SSD attached, and its resources are fully sufficient – I can even run other services on the very same little box without problems. A RaspberryPi or similar would also work easily. In it's release section, Gitea offers downloads for a wide range of architectures – and it's just a single file you drop in for installations and updates. I'm quite happy with it. What's more is it seems to scale very good: Codeberg.org is a community-driven hosting provider running on Gitea, so you can go there and take a look what Gitea looks like.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.