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)
g.pull()

(source)

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.