我在我的
Github中创建了新的存储库.
使用gitpython库我可以获得这个存储库.然后我创建新分支,添加新文件,提交并尝试推送到新分支.
请检查以下代码:
import git
import random
import os
repo_name = 'test'
branch_name = 'feature4'
remote_repo_addr_git = 'git@repo:DevOps/z_sandbox1.git'
no = random.randint(0,1000)
repo = git.Repo.clone_from(remote_repo_addr_git, repo_name)
new_branch = repo.create_head(branch_name)
repo.head.set_reference(new_branch)
os.chdir(repo_name)
open("parasol" + str(no), "w+").write(str(no)) # this is added
print repo.active_branch
repo.git.add(A=True)
repo.git.commit(m='okej')
repo.git.push(u='origin feature4')
一切正常,直到最后推动方法.我收到了这个错误:
stderr: ‘fatal: ‘origin feature4’ does not appear to be a git repository
fatal: Could not read from remote repository.Please make sure you have the correct access rights
and the repository exists.’
我可以从命令行运行此方法,它工作正常:
git puth -u origin feature4
但它在python中不起作用.你能告诉我我该怎么办?
最佳答案 这对我有用:
repo.git.push("origin", "feature4")