git push using python

Sam picture Sam · Jan 31, 2017 · Viewed 9k times · Source

I have local git repository. I am using python to commit the local repo using gitpython library. I want to push the commit to github. How can I do this using gitpython or any other library. I looked online but there was no solution available. Can anyone help me with this. Thanks in advance

Answer

Sam picture Sam · Jan 31, 2017
from git import Repo,remote

rw_dir = 'path/to/your/local/repo'
repo = Repo(rw_dir)

'''Enter code to commit the repository here.
After commit run the following code to push the commit to remote repo.
I am pushing to master branch here'''

origin = repo.remote(name='origin')
origin.push()