我看了一些参考资料,但仍有问题:
所以:Pushing local branch to remote branch - gitpython
所以:Use GitPython to Checkout a new branch and push to remote
相关问题:https://github.com/gitpython-developers/GitPython/issues/471
教程:https://gitpython.readthedocs.io/en/stable/tutorial.html
我对Git的理解是很基本的,请耐心等待。我想克隆一个远程repo,创建一个新的分支,并将新分支推回到remote。在
这似乎有效:
import git
import subprocess
nm_brnch = 'new_branch'
# Clone
repo_url = r'my_remote.git'
repo = git.Repo.clone_from(repo_url, dnm_wrk, branch=r'some_branch')
# Create new branch
git = repo.git
git.checkout('HEAD', b=nm_brnch)
# Push new branch to remote
subprocess.call(f'git push -u origin {nm_brnch}')
但很难看:(。我试了一下但没有成功:
^{pr2}$
我在Python3.7中使用
gitpython==2.1.11
。下面是我的push函数,其中我首先尝试高级push,然后根据需要进行低级push。注意我如何检查这两个命令的返回值。我还记录了推操作,这解释了每一步都发生了什么。在相关问题 更多 >
编程相关推荐