将本地分支推送到远程分支 [英] Pushing local branch to remote branch

查看:85
本文介绍了将本地分支推送到远程分支的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Github存储库中创建了新存储库.

I created new repository in my Github repository.

使用gitpython库,我可以获取此存储库.然后创建新分支,添加新文件,提交并尝试推送到新分支.

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.

请检查下面的代码:

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:'致命:'origin feature4'似乎不是git存储库致命的:无法从远程存储库读取.

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

但是它在Python中不起作用.

But it doesn't work in Python.

推荐答案

这对我有用:

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

这篇关于将本地分支推送到远程分支的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆