如何检出分支机构

时间:2019-05-10 20:16:47

标签: python gitpython

我让gitpython来克隆仓库,现在我需要签出该仓库内的分支,我一直在查看文档,但似乎找不到它

import git
import os
import shutil

DIR_NAME = "temp"
REMOTE_URL = "<REPO>"

if os.path.isdir(DIR_NAME):
    shutil.rmtree(DIR_NAME)

os.mkdir(DIR_NAME)

repo = git.Repo.init(DIR_NAME)
origin = repo.create_remote('origin', REMOTE_URL)
origin.fetch()
origin.pull(origin.refs[0].remote_head)

1 个答案:

答案 0 :(得分:0)

options.Events = new CookieAuthenticationEvents()
        {
            OnRedirectToLogin = (context) =>
            {
                context.HttpContext.Response.Redirect("http://staging.mysite.com/Account/Login?ReturnUrl=%2FHome%2FAuthorize");
                return Task.CompletedTask;
            }
        };

或者,如果分支尚不存在。.

repo.git.checkout('branchename')