Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to run a git command in python? [duplicate]

Tags:

git

python

I have been asked to write a script that pulls the latest code from Git, makes a build, and performs some automated unit tests.

I found that there are two built-in Python modules for interacting with Git that are readily available: GitPython and libgit2.

What approach/module should I use?

like image 786
user596922 Avatar asked Jan 18 '26 22:01

user596922


1 Answers

An easier solution would be to use the Python subprocess module to call git. In your case, this would pull the latest code and build:

import subprocess
subprocess.call(["git", "pull"])
subprocess.call(["make"])
subprocess.call(["make", "test"])

Docs:

  • subprocess - Python 2.x
  • subprocess - Python 3.x
like image 79
Ian Wetherbee Avatar answered Jan 21 '26 10:01

Ian Wetherbee