Search code examples
gitpython-3.xgit-pushgitpython

git push using python


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


Solution

  • 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()