Cloning git repo within an electron app, compiling a statically linked build of git

I need to be able to clone and checkout git repos for an electron (node.js) app I'm working on. The app is to be expected to run on Windows and popular Linux distros without requiring any external dependencies being preinstalled. This means I can't assume git will be installed and available on the command line.

I've tried these repos but ran into issues with each:

isomorphic-git - Seems to eat through memory like crazy when cloning and then crashes due to a lack of memory when trying to process a 1.8GB packfile.

nodegit - Either fails during app compilation or fails on app startup with errors seemingly all related to recent versions of electron/node. Can see many other people with same and similar problem in the GH issues but seems to be unresolved. Have tried multiple different versions with no luck.

wasm-git - Strange and awkward interface, can clone but it doesn't seem to come with a .git folder and can't figure out how to get checkout to work. Lack of docs and seems to have its own problems working inside electron.

simple-git - Seems like a nice, well written lib, but requires git either be preinstalled on the system or pointed to a custom git binary that it can interface with.

Bundling a portable git.exe with my app that I can either use directly or use with simple-git seems like the only option I have left, but I don't know how to get my hands on a small git.exe. The "portable" git for windows is 280MB after extraction, which is way too big for me to bundle.

Can anyone help me with building a statically linked version of git for Windows & Linux that isn't absolutely huge in file size? I know next to nothing about C or compiling C programs into binaries, let alone completely portable ones. Have tried flailing around trying to work out how to do it for hours but am getting nowhere fast.

Any other ideas for how I can clone & checkout a git repo within my app welcomed.


Your best bet is to use libgit2 and the bindings for Node.js. libgit2 is a library that can be compiled and run without any other dependencies and will provide most client-side Git functions, albeit at a lower level than command-line Git. It is widely used in a variety of contexts, although it lacks some features (like SHA-256 repository support).

The problem you'd likely encounter with Git on Windows is that Git requires POSIX tools, including a POSIX shell, to perform various functions. Windows lacks this functionality, so you have to ship it yourself, and even when you use something like Busybox, it still requires a bunch of space.

I will note that even if you use libgit2, you're still going to need to link a TLS library for your app to be minimally functional. On Windows, one is provided, but on Linux, I strongly recommend against statically linking a TLS library into your binary because they come out with security updates all the time, and you will instantly become responsible for updating your app immediately upon a new version coming out or your app will be a security problem.

Because typically these libraries (of which OpenSSL is the most popular) are not portable across Linux distros, you're going to need to ship a binary for each platform. You'd need to do that anyway, because if you're shipping Node or another runtime, it will also have a dependency on a TLS library and probably glibc, which will require this anyway.