我使用 GitPython 克隆主分支并签出功能分支,我进行本地更新、提交并推送回 git。代码片段如下所示,
注意:我的分支名称是 feature/pythontest
def git_clone():
repo = Repo.clone_from(<git-repo>, <local-repo>)
repo.git.checkout("-b", "feature/pythontest")
# I have done with file updates
repo.git.add(update=True)
repo.index.commit("commit")
origin = repo.remote(name="origin")
origin.push()
当我执行脚本时,出现以下错误,
To push the current branch and set the remote as upstream, use
git push --set-upstream origin feature/pythontest
要推送新分支,您需要运行git push --set-upstream origin branch_name
你可以阅读 git 文档中的 --set-upstreamhttps://git-scm.com/docs/git-push https://git-scm.com/docs/git-push这应该可以为 gitpython 完成工作:
def git_clone():
branch_name = "feature/pythontest"
repo = Repo.clone_from(<git-repo>, <local-repo>)
repo.git.checkout("-b", branch_name)
repo.git.add(repo.working_dir)
commit_output = repo.git.commit(m="Commit msg")
push_output = repo.git.push('--set-upstream', repo.remote().name, branch_name)
希望这可以帮助!
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)