42

I am looking at building an application with heavy ties to git..

Are there language bindings available and if so which are the most comprehensive?

Would it mean going to Bare Metal C?

Or does perl / python / php / C# have a set of full bindings?

Thanks

Daniel

Tao
  • 13,457
  • 7
  • 65
  • 76
Daniel Upton
  • 5,561
  • 8
  • 41
  • 64
  • Languages do not have source control bindings. IDEs do. – Oded Oct 27 '10 at 15:37
  • Haha yeah but i mean does the application have an API i can call on? or do i need to go write the stuff that interacts with git myself in C? – Daniel Upton Oct 27 '10 at 15:39
  • 3
    OK... so, you are looking for GIT _API_ bindings in different languages. – Oded Oct 27 '10 at 15:42
  • Yeah sorry if i was unclear.. will change the title now! thanks – Daniel Upton Oct 27 '10 at 15:44
  • I would *not* recommend java; while JGit/EGit are certainly under active development, they are nowhere near comprehensive. (Last time I looked, it was so bad that I'd consider it actively harmful to encourage someone to use EGit instead of git itself.) – Cascabel Oct 27 '10 at 15:59
  • Arguably, bash has the best binding, by definition, since it is the default language provided for interacting with git on windows, and it's the default shell on many linux systems. – Arafangion Jun 18 '11 at 07:34
  • "Best" is kind of subjective, IMO. It depends on what you are trying to accomplish. I've got a requirement right now that I need to support ``netstandard1.6``, if possible, and most *dotnet* efforts are either obsolete and support desktop *.NET Framework* or support ``netstandard2.0``, minimum. – mwpowellhtx Apr 04 '19 at 20:39

4 Answers4

77

There are three different approaches with respect to using Git from within some programming language:

  • Reimplementation of Git in different language. That is what the following projects do:

    • JGit which is reimplementation of Git in Java (used among others by EGit, the Eclipse Git plugin, and Gerrit Code Review),
    • Grit is Ruby library for extracting information from a git repository in an object oriented manner, which includes a partial native Ruby implementation. Used e.g. by GitHub.
    • GitSharp which is remplemantation of Git in C# for .NET and Mono, and which is following JGit wrt. functionality,
    • Dulwich which is pure-Python read-write implementation of the Git file formats and protocols.
    • Git::PurePerl is pure Perl interface to Git repositories (it was mostly based on Grit, initially).
    • Glip is "git library in PHP" - pure PHP implementation. Used by its author for eWiki.
    • NGit .NET port of JGit used by Monodevelop


    The problem with reimplementations is that they do not always implement the full functionality, and sometimes implement it wrong. On the other hand they are native, implement good performance; they may be licensed differently than C (original) implementation of Git, which is GPLv2.

  • Wrappers which call Git commands and wrap result it in some kind, suitably for target language.

    • The Git.pm module distributed with git (and used by some of its commands), Git::Wrapper and Git::Repository wrap git commands for Perl.
    • JavaGit is a Java API that provides access to git repositories via calling git commands.
    • GitPython is a Python library used to interact with Git repositories, by calling the Git executables and parsing output.
    • hs-libgit is Haskell wrapper for git.


    The problem with wrappers is that they can be slow (they require forking a git process), and that they require git to be installed to work.

    Note also that git itself is highly scriptable (e.g. using shell scripts), thanks to the fact that beside higher level commands meant for end user (porcelain) it also provides low level commands meant for scripting (plumbing).

  • Finally there are bindings to libgit2, which means to be re-entrant linkable library with a solid API (was Google Summer of Code 2010 project).

    • libgit2 itself is a portable, pure C implementation.
    • Rugged - Ruby bindings.
    • php-git - PHP bindings.
    • luagit2 - Lua bindings.
    • GitForDelphi - Delphi bindings.
    • libgit2sharp - .NET bindings.
    • pygit2 - Python bindings.
    • Geef is a simple Erlang NIF that exposes some of the libgit2 library functions to Erlang. Monodevelop uses a .NET port for JGit


    Libgit2 is quite new project; it is work in progress, so not everything is implemented at the time of being. See libgit2 homepage for details.

All this information can be found at InterfacesFrontendsAndTools page on Git Wiki

Josh Buedel
  • 1,853
  • 16
  • 41
Jakub Narębski
  • 309,089
  • 65
  • 217
  • 230
  • Note that if I remember correctly authors of GitSharp / Git# moved from their own (re)implementation of Git to translating JGit from Java to .NET – Jakub Narębski Jun 25 '11 at 18:01
  • 1
    NGit is probably in the wrong section, as it is (mostly) an automated translation of JGit into C#. It should likely fall under the Reimplementation category as it doesn't spawn a git process like the wrappers do. – Dan Rigby Sep 07 '11 at 20:26
  • 3
    It's worth noting that at some point in the 4+ years since this was written, the GitSharp developers have put the project on hold to work on libgit2Sharp. "GitSharp is a quite usable and stable library used by several projects to interact with git repositories. To get an idea check out the Demo (see below)! GitSharp development is currently on hold because we believe that the libgit2 project and its C# bindings libgit2sharp are far more promising to work on." [GitSharp](http://www.eqqon.com/index.php/GitSharp) – RubberDuck Jan 23 '15 at 00:49
2

You might try not using an API. git is structured as a suite of utilities at different levels of abstraction. You should be able to build a comprehensive set of utilities which work by calling out to these utilities and processing their output. Many of the high-level git commands are shell scripts or perl scripts which do just this, so you have plenty of examples in the git source itself to use as examples.

Good examples to start with:

  • magit : git interface for emacs written in emacs lisp

  • git gui : tcl, comes with git

  • gitk : tcl, also comes with git

  • gitview : python, comes with git in the contrib directory.

  • tig : C, text-mode history browswer for git.

Tim Schaeffer
  • 2,616
  • 1
  • 16
  • 20
1

Depends what you want, by the looks of it your most comfortable with C/C#. Git is written in C, so if you want speed then maybe you should go with that. But if you want code clarity and ease of writing GitSharp is probably a better option.

Joe D
  • 2,855
  • 2
  • 31
  • 25
  • Ah ok cool =) Yeah.. not so much C but im a quick learner and a bit of a nerd and i have experice with objective-c which is c and a couple add-ons really, My C# skills are pretty good, my main question now is how good is git sharp.. could i in theory write a github competitor with it? (I Wont) but is it powerful enough? – Daniel Upton Oct 27 '10 at 17:11
0

I'm not sure if it is the best, but for .net there is GitSharp

Pondidum
  • 11,457
  • 8
  • 50
  • 69
  • Thanks.. .Net is preferable actually, Have you used it? Whats it Like? – Daniel Upton Oct 27 '10 at 15:49
  • Great. Now somebody is combining the least portable VCS with the least portable language framework. Does it get any worse? – Matt Joiner Oct 27 '10 at 15:50
  • 3
    @Daniel: Not extensively, I have downloaded it and just had a look through it, but it seems to be fairly straight forward. @Matt: If your going to be like that I recommend using the ignore-tag feature on C# and Git! – Pondidum Oct 27 '10 at 15:52
  • @Matt Joiner: you may have a point about .net (though I doubt it's the worst), but really, git not portable? What platform does it not work on? – Cascabel Oct 27 '10 at 15:53
  • 2
    Hahaha.. No Flamewar Please! As much as everyone hates to hear it, a whole bunch of big corporates are running a Microsoft Only Development shop and using Visual Source Shredder! The Only Reason they Wont Switch to git setting up a central server wihtout a management tool makes them nervous and they dont get distibuted version control! – Daniel Upton Oct 27 '10 at 16:02
  • @Daniel: Of course, even if *your* company is Microsoft-only, you'll be able to attract more developers (assuming this is open-source) and users if your particular project is portable. I know you may not ultimately go that route, but definitely something to keep in mind. – Cascabel Oct 27 '10 at 16:09
  • @MattJoiner I'd say ObjectiveC is less portable than c# thanks to mono...I've had tons of success working with mono. Most of the time you don't even need to compile your project any differently, just build it, slap it on another system, and have mono call it. – Kelly Elton Jan 06 '13 at 17:14