切分支的

This commit is contained in:
luojian 2025-08-01 15:48:16 +08:00
parent de271eb6b4
commit fc46fb68d6
1 changed files with 10 additions and 5 deletions

View File

@ -34,6 +34,11 @@ class ProjectInit(Task):
repo.git.fetch(remote_name)
if repo.active_branch.name != branch_name:
# 检查本地是否已存在该分支
if branch_name in repo.heads:
# 本地分支已存在,直接切换
repo.heads[branch_name].checkout()
else:
# 2. 创建本地分支并跟踪远程分支
remote_branch_ref = f"{remote_name}/{branch_name}"
local_branch = repo.create_head(branch_name, remote_branch_ref) # 创建本地分支指向远程