Search code examples
pythongitjgitgitpython

Python - A Git module which doesn't depend on the git binary file


I need a Python module which does not depend on the Git binary file. It should manipulate the index on its own, without making use of the git commands. Following are the basic requirements.

  1. Clone
  2. Commit
  3. Push to remote
  4. Handle authentication with username and password, and keys
  5. Pull and checkout files

As far as I know, GitPython and Gittle needs the git binary file. I'm looking for a python alternative for JGit which doesn't make use of the git binary.


Solution

  • Dulwich is an option. Quoting the project description:

    Dulwich is a Python implementation of the Git file formats and protocols, which does not depend on Git itself.

    Since Dulwich implements Git file formats and protocols it is rather low-level. The docs include a tutorial describing how files can be staged and committed. A later tutorial chapter describes how to work with remote repositories.

    Authentication is not explicitly discussed in any tutorials, but assuming you can use HTTP Basic you should be able to get going with Dulwich, which supports the HTTP protocol. The library also claims to support Git+SSH.