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
🌐
Readthedocs
gitpython.readthedocs.io
GitPython Documentation — GitPython 3.1.46 documentation
0.3.4 - Python 3 Support · 0.3.3 · 0.3.2.1 · 0.3.2 · 0.3.2 RC1 · 0.3.1 Beta 2 · 0.3.1 Beta 1 · 0.3.0 Beta 2 · 0.3.0 Beta 1 · 0.2 Beta 2 · 0.2 · 0.1.6 · 0.1.5 · 0.1.4.1 · 0.1.4 · 0.1.2 · 0.1.1 · 0.1.0 · Index · Module Index ·
🌐
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. - gitpython-developers/GitPython
Starred by 5.1K users
Forked by 968 users
Languages   Python
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
🌐
PyPI
pypi.org › project › GitPython
GitPython · PyPI
GitPython is a Python library used to interact with Git repositories
      » pip install GitPython
    
Published   Jan 01, 2026
Version   3.1.46
🌐
Readthedocs
gitpython.readthedocs.io › en › stable › tutorial.html
GitPython Tutorial — GitPython 3.1.46 documentation
from git import Repo # rorepo is a Repo instance pointing to the git-python repository. # For all you know, the first argument to Repo is a path to the repository you # want to work with.
Find elsewhere
🌐
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
🌐
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.
🌐
PDX
web.pdx.edu › ~gjay › teaching › mth271_2020 › html › 03_Working_with_git.html
Git Repo class in python
If you want to know more about git, there are many resources online, such as the Git Handbook. The most common way to fetch materials from a remote repository is using git's command line tools, but for our purposes, the python code in this notebook will suffice. We shall use the python module gitpython to work with git.
🌐
Full Stack Python
fullstackpython.com › blog › first-steps-gitpython.html
First Steps with GitPython - Full Stack Python
November 30, 2017 - Our Git repository and path environment variable are all set so let's write the Python code that uses GitPython. Create a new Python file named read_repo.py and open it so we can start to code up a simple script. ... The os module makes it easy to read environment variables, such as our GIT_REPO_PATH variable we set earlier.
🌐
Python Developer's Guide
devguide.python.org › contrib › workflows › install-git
Install Git
[This is the Install Git section from the devguide.] CPython is developed using Git for version control. The Git command line program is named git; this is also used to refer to Git itself. Git is ...
🌐
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 - Python Module Index · 175 · Index · 177 · iv · CHAPTER · ONE · OVERVIEW / INSTALL · GitPython is a python library used to interact with git repositories, high-level like git-porcelain, or low-level like git- plumbing. It provides abstractions of git objects for easy access of repository ...
🌐
LinuxConfig
linuxconfig.org › home › how to manage git repositories with python
Manage Git Repositories with Python: GitPython Guide
May 27, 2022 - In this tutorial we learned how to start working with git repositories using Python and the GitPython library. We saw how to clone or initialize a repository, how to add remotes, how to create commits and how to push and pull to and from the remote. We also saw how to check if a repository has changes and how to manage its submodules.
🌐
Readthedocs
gitpython.readthedocs.io › en › stable › reference.html
API Reference — GitPython 3.1.46 documentation
__module__ = 'git.objects.base' · __ne__(other: Any) → bool · Returns: True if the objects do not have the same SHA1 · __repr__() → str · Returns: String with pythonic representation of our object · __slots__ = ('repo', 'binsha', 'size') ·
🌐
Waylon Walker
waylonwalker.com › python-git
Using Git from Python - Waylon Walker
April 30, 2022 - It provides abstractions of git objects for easy access of repository data, and additionally allows you to access the git repository more directly using either a pure python implementation, or the faster, but more resource intensive git command ...
🌐
Python Developer's Guide
devguide.python.org › gitbootcamp
Git bootcamp and cheat sheet
You should have been redirected · If not, click here to continue
🌐
GeeksforGeeks
geeksforgeeks.org › python › automating-some-git-commands-with-python
Automating some git commands with Python - GeeksforGeeks
April 28, 2025 - To start automating Git commands with Python, you will first need to install GitPython by running the following command:
🌐
Readthedocs
gitpython.readthedocs.io › en › 0.3.3 › tutorial.html
GitPython Tutorial — GitPython 0.3.3 documentation
Submodules can be conveniently handled using the methods provided by Git-Python, and as an added benefit, Git-Python provides functionality which behave smarter and less error prone than its original c-git implementation, that is Git-Python tries hard to keep your repository consistent when ...