Skip to content

Perform ‘git pull’ in Python

I currently don’t have a good example where this would be useful, but it’s certainly possible, in multiple ways. The first way is to use the subprocess library:

import subprocess
process = subprocess.Popen(["git", "pull"], stdout=subprocess.PIPE)
output = process.communicate()[0]

Or you could use GitPython, a popular git library for Python:

import git 

g = git.cmd.Git(git_dir)


Leave a Reply

