Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pushing local branch to remote branch

I created new repository in my Github repository.

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.

like image 200
Borys Wisniewski Avatar asked Oct 11 '16 07:10

Borys Wisniewski


1 Answers

This worked for me:

repo.git.push("origin", "feature4")
like image 95
ParisFA Avatar answered Sep 22 '22 10:09

ParisFA