如何结帐一个分支
How to Checkout out a branch
我让 gitpython 克隆了一个 repo,现在我需要检查那个 repo 中的分支我一直在查看文档,但似乎找不到它
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)
repo.git.checkout('branchename')
或者,如果分支尚不存在..
repo.git.checkout('-b', 'branchename')
我让 gitpython 克隆了一个 repo,现在我需要检查那个 repo 中的分支我一直在查看文档,但似乎找不到它
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)
repo.git.checkout('branchename')
或者,如果分支尚不存在..
repo.git.checkout('-b', 'branchename')