The Simplest Way To Use Git In Python Gitpyton Git Class
Apr 16, 2021
usecase
The aim of this how-to-guide🏁 is to make git working in Python scripts fast for simple tasks.
1. steps
- install gitPython
- import the module with
import git
- use the
Git
class and pass commands withgit.Git().<gitCommand>(<param1>, <param2>, ...)
- to get output in CLI, embed into a
print
statement
2. examples
- this is for
git pull orogin master
import git
print(' UPDATES '.center(80, '~'))
print(git.Git().pull('origin', 'master'))
- output
~~~~~~~~~~~~~~~~~~ UPDATES ~~~~~~~~~~~~~~~~~~~~~~~
Already up to date.