首页 > 解决方案 > pygit2:如何“git remote set-branches origin remote_branch_name”

问题描述

标题说明了一切。我正在使用pygit2并试图弄清楚如何使用 git cli 实现以下操作: git remote set-branches origin remote_branch_name

标签: pythongitpygit2

解决方案


如果直接设置配置可能更简单(因为pygit2 Remotes没有明显的方法来设置获取 URL)
使用Config.set_multivar(name, regex, value)

repo_obj = pygit2.Repository(repopath)
repo_obj.config.set_multivar(
        'remote.origin.fetch',
        '',
        '+refs/heads/remote_branch_name:refs/remotes/myOrigin/remote_branch_name'
    )

推荐阅读