python - 如何使用 Pygithub 结帐到新分支?

标签 python github github-api pygithub

这是我学到的,

g = Github("user", "pass")
repoName = "apiTest"
print "Get all repos:"
for repo in g.get_user().get_repos():
print "\t%s" % repo.name

print "<--------------------------------------------------->"

print "Get all branches in repo %s:" % repoName
for branch in g.get_user().get_repo(repoName).get_branches():
print "\t%s" % branch.name

print "<--------------------------------------------------->"

print "Get last commit message in repo %s:" % repoName
branch = g.get_user().get_repo(repoName).get_branch("dev")
lastCommit = branch._commit.value.commit
print "\t%s" % lastCommit._message.value
print "\t%s"

print "<--------------------------------------------------->"
fc = repo.update_file("/README.md", "testing PyGithub", "test commit", fc.sha)
print fc

但我想知道如何结帐到新的分支机构。我没有在网上找到任何例子。非常感谢。

最佳答案

您可以使用 PyGithub 的 create_git_ref 函数来创建一个新的分支。使用上面的示例:

g = Github("user", "pass")
repoName = "apiTest"
source_branch = 'master'
target_branch = 'newfeature'

repo = g.get_user().get_repo(repoName)
sb = repo.get_branch(source_branch)
repo.create_git_ref(ref='refs/heads/' + target_branch, sha=sb.commit.sha)

关于python - 如何使用 Pygithub 结帐到新分支?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46120240/

相关文章:

python - 谷歌视频情报 python 教程 : where to place credential key. json?

python - 要求正整数并验证输入的简单函数

ios - 错误 : git-credential-osxkeychain died of signal 11

git - 如何通过他们的 API 重命名 GitHub 存储库?

javascript - 如何在浏览器中将 octokat.js 与 webpack 一起使用?

javascript - JSONP 和 Github API v3 的问题

python - 如何仅过滤包含一周数据的列中的第一个星期五(Pandas)

python - 不同的领域可以使用不同的方言吗?

git - 在子模块中使用子模块

git - 替换到另一台 PC 后无法推送到 github repo