While this question was asked a while ago and I don't know the state of the libraries at that point, it is worth mentioning for searchers that GitPython does a good job of abstracting the command line tools so that you don't need to use subprocess. There are some useful built in abstractions that you can use, but for everything else you can do things like:

import git
repo = git.Repo( '/home/me/repodir' )
print repo.git.status()
# checkout and track a remote branch
print repo.git.checkout( 'origin/somebranch', b='somebranch' )
# add a file
print repo.git.add( 'somefile' )
# commit
print repo.git.commit( m='my commit message' )
# now we are one commit ahead
print repo.git.status()

Everything else in GitPython just makes it easier to navigate. I'm fairly well satisfied with this library and appreciate that it is a wrapper on the underlying git tools.

UPDATE: I've switched to using the sh module for not just git but most commandline utilities I need in python. To replicate the above I would do this instead:

import sh
git = sh.git.bake(_cwd='/home/me/repodir')
print git.status()
# checkout and track a remote branch
print git.checkout('-b', 'somebranch')
# add a file
print git.add('somefile')
# commit
print git.commit(m='my commit message')
# now we are one commit ahead
print git.status()
Answer from underrun on Stack Overflow
🌐
GitHub
github.com › gitpython-developers › GitPython
GitHub - gitpython-developers/GitPython: GitPython is a python library used to interact with Git repositories. · GitHub
GitPython is a python library used to interact with git repositories, high-level like git-porcelain, or low-level like git-plumbing.
Starred by 5.1K users
Forked by 968 users
Languages   Python
🌐
Readthedocs
gitpython.readthedocs.io
GitPython Documentation — GitPython 3.1.46 documentation
git.Repo · Trees & Blobs · Usage · More Resources · GitPython Tutorial · Meet the Repo type · Examining References · Modifying References · Understanding Objects · The Commit object · The Tree object · The Index Object · Handling Remotes · Submodule Handling ·
Discussions

Best git module for python?
pygit2 is the only one I've used, and it worked well for me. More on reddit.com
🌐 r/Python
5
3
June 29, 2017
Automatically increment version on package release?

However you end up triggering it, I recommend you use bumpversion to actually do the bumping.

More on reddit.com
🌐 r/Python
7
1
February 24, 2016
Python library for pulling remote git metadata without cloning the repo locally?
I have used python-gitlab for this. That was obviously for gitlab but for whatever repo host you're using you can check if their is a package. Or they will usually at least have an api you can use to get this info More on reddit.com
🌐 r/git
9
2
July 12, 2020
aiowmi - A Python WMI library
What are the differences to the decades old WMI module by Tim Golden? http://timgolden.me.uk/python/wmi/contents.html More on reddit.com
🌐 r/Python
3
11
March 11, 2022
Top answer
1 of 11
136

While this question was asked a while ago and I don't know the state of the libraries at that point, it is worth mentioning for searchers that GitPython does a good job of abstracting the command line tools so that you don't need to use subprocess. There are some useful built in abstractions that you can use, but for everything else you can do things like:

import git
repo = git.Repo( '/home/me/repodir' )
print repo.git.status()
# checkout and track a remote branch
print repo.git.checkout( 'origin/somebranch', b='somebranch' )
# add a file
print repo.git.add( 'somefile' )
# commit
print repo.git.commit( m='my commit message' )
# now we are one commit ahead
print repo.git.status()

Everything else in GitPython just makes it easier to navigate. I'm fairly well satisfied with this library and appreciate that it is a wrapper on the underlying git tools.

UPDATE: I've switched to using the sh module for not just git but most commandline utilities I need in python. To replicate the above I would do this instead:

import sh
git = sh.git.bake(_cwd='/home/me/repodir')
print git.status()
# checkout and track a remote branch
print git.checkout('-b', 'somebranch')
# add a file
print git.add('somefile')
# commit
print git.commit(m='my commit message')
# now we are one commit ahead
print git.status()
2 of 11
87

I thought I would answer my own question, since I'm taking a different path than suggested in the answers. Nonetheless, thanks to those who answered.

First, a brief synopsis of my experiences with GitPython, PyGit, and Dulwich:

  • GitPython: After downloading, I got this imported and the appropriate object initialized. However, trying to do what was suggested in the tutorial led to errors. Lacking more documentation, I turned elsewhere.
  • PyGit: This would not even import, and I could find no documentation.
  • Dulwich: Seems to be the most promising (at least for what I wanted and saw). I made some progress with it, more than with GitPython, since its egg comes with Python source. However, after a while, I decided it may just be easier to try what I did.

Also, StGit looks interesting, but I would need the functionality extracted into a separate module and do not want wait for that to happen right now.

In (much) less time than I spent trying to get the three modules above working, I managed to get git commands working via the subprocess module, e.g.

def gitAdd(fileName, repoDir):
    cmd = ['git', 'add', fileName]
    p = subprocess.Popen(cmd, cwd=repoDir)
    p.wait()

gitAdd('exampleFile.txt', '/usr/local/example_git_repo_dir')

This isn't fully incorporated into my program yet, but I'm not anticipating a problem, except maybe speed (since I'll be processing hundreds or even thousands of files at times).

Maybe I just didn't have the patience to get things going with Dulwich or GitPython. That said, I'm hopeful the modules will get more development and be more useful soon.

🌐
PyPI
pypi.org › project › GitPython › 0.3.2
GitPython
JavaScript is disabled in your browser. Please enable JavaScript to proceed · A required part of this site couldn’t load. This may be due to a browser extension, network issues, or browser settings. Please check your connection, disable any ad blockers, or try using a different browser
🌐
Readthedocs
gitpython.readthedocs.io › en › stable › intro.html
Overview / Install — GitPython 3.1.46 documentation
GitPython is a python library used to interact with git repositories, high-level like git-porcelain, or low-level like git-plumbing.
🌐
PyPI
pypi.org › project › GitPython
GitPython · PyPI
GitPython is a python library used to interact with git repositories, high-level like git-porcelain, or low-level like git-plumbing.
      » pip install GitPython
    
Published   Jan 01, 2026
Version   3.1.46
Find elsewhere
🌐
Grimoire
grimoire.carcano.ch › the grimoire of a modern linux professional › blog › dev-ops tools › scripting › git with python howto gitpython tutorial and pygit2 tutorial
Git With Python HowTo GitPython Tutorial And PyGit2 Tutorial
November 14, 2024 - Probably the most used library and of course one of the earliest, it is a wrapper around the "git" command line utility providing an object model representing Git concepts and offering error handling. For this reason GitPython needs the "git" executable to be installed on the system and available in your "PATH" environment variable or in the "GIT_PYTHON_GIT_EXECUTABLE" environment variable.
🌐
Readthedocs
gitpython.readthedocs.io › en › stable › tutorial.html
GitPython Tutorial — GitPython 3.1.46 documentation
All code presented here originated from test_docs.py to assure correctness. Knowing this should also allow you to more easily run the code for your own testing purposes. All you need is a developer installation of git-python.
🌐
Anaconda.org
anaconda.org › anaconda › gitpython
gitpython - anaconda
Organization created on Sep 18, 2015 · Anaconda, Inc. Austin, Texas The packages on this channel are covered by the Anaconda repository Terms of Service. Among other things, the ToS prohibits heavy commercial use and mirroring by any third party for commercial purposes
🌐
Full Stack Python
fullstackpython.com › blog › first-steps-gitpython.html
First Steps with GitPython - Full Stack Python
November 30, 2017 - GitPython is a Python code library for programmatically reading from and writing to Git source control repositories.
🌐
PyPI
pypi.org › project › python-git
python-git
JavaScript is disabled in your browser. Please enable JavaScript to proceed · A required part of this site couldn’t load. This may be due to a browser extension, network issues, or browser settings. Please check your connection, disable any ad blockers, or try using a different browser
🌐
GitHub
github.com › jelmer › dulwich
GitHub - jelmer/dulwich: Pure-Python Git implementation · GitHub
It aims to provide an interface to git repos (both local and remote) that doesn't call out to git directly but instead uses pure Python.
Starred by 2.2K users
Forked by 428 users
Languages   Python
🌐
Blue Book
lyz-code.github.io › blue-book › coding › python › gitpython
GitPython - The Blue Book
GitPython is a python library used to interact with git repositories, high-level like git-porcelain, or low-level like git-plumbing.
🌐
LinuxConfig
linuxconfig.org › home › how to manage git repositories with python
Manage Git Repositories with Python: GitPython Guide
May 27, 2022 - Neither Python nor Git need ... we interact with git repositories using the git binary; when we need to work with them using Python, instead, we can use the GitPython library....
🌐
Python Developer's Guide
devguide.python.org › gitbootcamp
Git bootcamp and cheat sheet
You should have been redirected · If not, click here to continue
🌐
Read the Docs
app.readthedocs.org › projects › gitpython › downloads › pdf › stable pdf
GitPython Documentation Release 3.1.46 Michael Trier Jan 01, 2026
January 1, 2026 - GitPython is a python library used to interact with git repositories, high-level like git-porcelain, or low-level like git-
🌐
GeeksforGeeks
geeksforgeeks.org › python › automating-some-git-commands-with-python
Automating some git commands with Python - GeeksforGeeks
April 28, 2025 - However, managing Git repositories can be a tedious task, especially when working with multiple branches and commits. Fortunately, Git's command-line interface can be automated using Python, making it easier to manage your code and automate common tasks. One popular library for automating Git commands with Python is GitPython.
🌐
Pygit2
pygit2.org
pygit2 - libgit2 bindings in Python — pygit2 1.19.1 documentation
Bindings to the libgit2 shared library, implements Git plumbing. Supports Python 3.11 to 3.14 and PyPy3 7.3+