2012-10-31 11 views
8

gitPythonを使用してgitリポジトリを取得する方法を探しています。 これまでのところ、これは私が公式の文書hereから取ったものです。GitPythonでリモートリポジトリを取得するには?

test_remote = repo.create_remote('test', '[email protected]: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() 

事実が、私は名前を変更withouthプルを行うにはrepo.remotes.originにアクセスしたいということです、それは私がこれを達成するにはどうすればよいの原点(origin.rename) ですか?おかげさまで

答えて

15

私が直接レポ名を取得することによって、これを管理する:受け入れ答えとして

repo = git.Repo('repo_name') 
o = repo.remotes.origin 
o.pull() 
+0

ここの 'repo_name'は実際にはリポジトリの名前ではなく、gitリポジトリのベースへのファイルシステムのパスです。 –

0

は、repo.remotes.origin.pull()を使用することが可能だと言うが、欠点は、それはそれ自身の一般的なエラーに実際のエラーメッセージを隠していることです。

git.exc.GitCommandError: 'git pull' returned with exit code 1 
stderr: 'ssh: Could not resolve hostname github.com: Name or service not known 
fatal: Could not read from remote repository. 

Please make sure you have the correct access rights 
and the repository exists.' 
0

は、あなたが探しているホープ:

一方
git.exc.GitCommandError: 'Error when fetching: fatal: Could not read from remote repository. 
' returned with exit code 2 

repo.git.pull()ようusing git commands with GitPythonは、実際のエラーを示しています。DNS解決は機能しません。たとえば、その後、repo.remotes.origin.pull()は、次のエラーメッセージが表示さこれは、

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

指定されたリポジトリとブランチの最新のコミットをプルします。

関連する問題