Menu

1 / 2

GitPython

DEV Community·MEROLINE LIZLENT·6 months ago
#Pam9EJnf
#reading#gitlab#git#github#repo
Reading 0:00
15s threshold

Have you ever written a deployment script with subprocess.run(["git", "pull"]) and felt like there just must be a better way? There is! GitPython provides you with a real Python API for doing anything Git can do: clone, commit, create branches, diffs, read history, etc.

Installation

pip install gitpython

Enter fullscreen mode

Exit fullscreen mode

GitPython assumes you have git installed on your system. It uses shelling out to git behind the scenes, translating into Python objects as cleanly as possible.

Opening a Repository

from git import Repo , InvalidGitRepositoryError

# Open an existing repo repo = Repo ( " /path/to/your/project " )

# Open the repo at the current working directory repo = Repo ( " . " )

# Open from any subdirectory (search_parent_directories=True) repo = Repo ( " .…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.