Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I pull a remote repository with GitPython?

Tags:

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 it's origin (origin.rename) How can I achieve this? Thanks.

like image 866
Uuid Avatar asked Oct 31 '12 20:10

Uuid


People also ask

How do I pull a remote repository?

The content of the multiple remote repositories can be pulled to the local drive by using the command, `git pull origin` or `git pull upstream`.

How do I find my current remote repository?

You can view that origin with the command git remote -v, which will list the URL of the remote repo.

How do I find the remote URL for a repository?

Getting The Remote URL For a Git Repository If you're unsure what the remote is called, simply run “ git remote ,” which will print all of them.

How do I pull changes from remote repo to local repository?

The git pull command is used to fetch and download content from a remote repository and immediately update the local repository to match that content. Merging remote upstream changes into your local repository is a common task in Git-based collaboration work flows.


2 Answers

I managed this by getting the repo name directly:

 repo = git.Repo('repo_path')  o = repo.remotes.origin  o.pull() 
like image 85
Uuid Avatar answered Oct 22 '22 03:10

Uuid


Hope you are looking for this :

import git g = git.Git('git-repo') g.pull('origin','branch-name') 

Pulls latest commits for the given repository and branch.

like image 37
Akhil Singhal Avatar answered Oct 22 '22 04:10

Akhil Singhal