我在我的 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: '致命: 'origin feature4' 似乎不是 git 存储库
致命:无法从远程存储库读取。
请确保您拥有正确的访问权限
并且存储库存在。
我可以从命令行运行此方法并且工作正常:
git puth -u origin feature4
但它在 Python 中不起作用。
这对我有用:
repo.git.push("origin", "feature4")
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)