pygit2无法将本地分支设置为上游分支

时间:2020-10-22 14:11:20

标签: python git git-checkout gitpython pygit2

我在python中使用Pygit2签出到特定分支。类似于git;但是,我无法将新签出的分支设置为远程分支(设置为上游)。

PyGit2代码:

  • 下面的PyGit2代码中缺少将我的本地分支设置为上游的命令是什么?
remote_regex = re.compile('^refs/remotes/origin/')
try:
  repo.checkout_tree(treeish = checkout_commit,strategy = pygit2.GIT_CHECKOUT_SAFE | pygit2.GIT_CHECKOUT_RECREATE_MISSING)
  # For head to point to the commit/tag
  checkout_branch_local = "refs/heads/{!s}".format(checkout_branch)
  if reference_type == Reference.COMMIT or reference_type == Reference.TAG:
    repo.set_head(pygit2.Oid(hex=checkout_commit.hex))
  else:
    repo.set_head(checkout_branch_local)
    if remote_regex.match(branch_git_ref_name):
      # Create reference between remote and local branch, essentially setting branch up-stream
      repo.create_reference(checkout_branch_local, checkout_commit.hex)

except Exception as e:
  logging.error("Could not complete checkout for repository at path {!s} [{!s}]".format(os.path.basename(absolute_repo_path), e))
  raise Exception("Check-Out Error")

等效的Git命令:

git checkout -b branch-XYZ

切换到新的分支“ branch-XYZ”

git status

在分支XYZ上 没什么要提交的,正在工作的树很干净

git branch
  • 分支-XYZ 大师
git pull

当前分支没有跟踪信息。 请指定您要合并的分支。 有关详细信息,请参见git-pull(1)。

git pull <remote> <branch>

如果您希望为此分支机构设置跟踪信息,可以使用以下方法进行

git branch --set-upstream-to=origin/<branch> branch-XYZ
  • 我想对PyGit2执行相同的行为,以将本地分支设置为远程分支(上游)
  • 什么是PyGit2等同于:“ git branch --set-upstream-to = origin / branch-XYZ”

0 个答案:

没有答案