Cloning git repo within an electron app, compiling a statically linked build of git - TagMerge
4Cloning git repo within an electron app, compiling a statically linked build of gitCloning git repo within an electron app, compiling a statically linked build of git

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

Asked 1 years ago
2
4 answers

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.

Source: link

1

I'm the author of wasm-git, but first let me say that wasm-git is just a port of libgit2 to WebAssembly using Emscripten. This means that for documentation on how to interact with files, you need to look in the emscripten filesystem docs, and if you want to expose more functionality of libgit2, you need to look into the libgit2 examples and docs.

For examples on how to use wasm-git from nodejs, you can see the tests here: https://github.com/petersalomonsen/wasm-git/tree/master/test

there are also other test folders in there showing how to use from the browser, with and without (using emscripten asyncify) a webworker.

Wasm-git does not need git installed, and it can clone, checkout and several other git operations. I have not tested it with electron, but the test cases found in the repository works in browsers and nodejs.

Source: link

0

An example demonstrating using git clone can be found on the setting up a repository guide. The example below demonstrates how to obtain a local copy of a central repository stored on a server accessible at example.com using the SSH username john:
git clone ssh://john@example.com/path/to/my-project.git cd my-project # Start working on the project
Cloning to a specific folder
git clone <repo> <directory>
Cloning a specific tag
git clone --branch <tag> <repo>
Shallow clone
git clone -depth=1 <repo>
git clone -branch new_feature git://remoterepository.git

Source: link

0

Type git clone, and then paste the URL you copied earlier.
$ git clone https://github.com/YOUR-USERNAME/YOUR-REPOSITORY
Press Enter to create your local clone.
$ git clone https://github.com/YOUR-USERNAME/YOUR-REPOSITORY
> Cloning into `Spoon-Knife`...
> remote: Counting objects: 10, done.
> remote: Compressing objects: 100% (8/8), done.
> remove: Total 10 (delta 1), reused 10 (delta 1)
> Unpacking objects: 100% (10/10), done.
To clone a repository locally, use the repo clone subcommand. Replace the repository parameter with the repository name. For example, octo-org/octo-repo, monalisa/octo-repo, or octo-repo. If the OWNER/ portion of the OWNER/REPO repository argument is omitted, it defaults to the name of the authenticating user.
gh repo clone repository
You can also use the GitHub URL to clone a repository.
gh repo clone https://github.com/cli/cli
Type git clone, and then paste the URL you copied earlier.
$ git clone https://github.com/YOUR-USERNAME/YOUR-REPOSITORY

Source: link

Recent Questions on git

    Programming Languages