Search code examples
pythongitgitpython

How can I pull a remote repository with GitPython?


I am trying to find the way to pull a git repository using gitPython. So far this is what I have taken from the official docs here.

test_remote = repo.create_remote('test', 'git@server:repo.git')
repo.delete_remote(test_remote) # create and delete remotes
origin = repo.remotes.origin    # get default remote by name
origin.refs                     # local remote references
o = origin.rename('new_origin') # rename remotes
o.fetch()                       # fetch, pull and push from and to the remote
o.pull()
o.push()

The fact is that I want to access the repo.remotes.origin to do a pull withouth renaming its origin (origin.rename). How can I achieve this?


Solution

  • I managed this by getting the repo name directly:

     repo = git.Repo('repo_path')
     o = repo.remotes.origin
     o.pull()