The Simplest Way To Use Git In Python Gitpyton Git Class

usecase

The aim of this how-to-guide🏁 is to make git working in Python scripts fast for simple tasks.

1. steps

  1. install gitPython
  2. import the module with import git
  3. use the Git class and pass commands with git.Git().<gitCommand>(<param1>, <param2>, ...)
  4. 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.

3. sources

Infrastructure Support Engineer/Technical Writer (Snowplow Analytics) with a passion for Python/writing documentation. More about me: https://pavol.kutaj.com

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

How to download all the files in an AWS S3 Bucket?

How to Use Asp.Net Technologies to Develop web applications?

Microservices Best Practices Every Developer Should Follow

Apollo Cache in a Nutshell

Why property Wrappers are so important in Swift?

How to buy eggs in My DeFi Pet?

Most Useful Kakoune Navigation Commands

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Pavol Kutaj

Pavol Kutaj

Infrastructure Support Engineer/Technical Writer (Snowplow Analytics) with a passion for Python/writing documentation. More about me: https://pavol.kutaj.com

More from Medium

Iterative Design with Python

The Parameters And Usage Of Ranges In Python

Get Started with Python in VSCode on Debian and Ubuntu-based distributions

How to create the first python package