Pushing local branch to remote branch - gitpython

↘锁芯ラ 提交于 2019-12-06 06:18:32

问题


I created new repository in my Github. Using the gitpython library i'm able to get this repository. Then I create new branch, add new file, commit and try to push to the new branch.

Please check be code below:

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')

Everything working fine until last push method. I got this error:

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.'

I'm able to run this method from command line and it's working fine:

git puth -u origin feature4

But it doesn't work in python. Could you please tell me what should I do ?


回答1:


This worked for me:

repo.git.push("origin", "feature4")


来源:https://stackoverflow.com/questions/39972525/pushing-local-branch-to-remote-branch-gitpython

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!