编程语言
首页 > 编程语言> > python合并master到各开发分支

python合并master到各开发分支

作者:互联网

from git import Repo
from git import Git

conflict_branch = []
# 路径
repo = Repo("D:/gitlab-1/lis")
gitlab = Git("D:/gitlab-1/lis")
# print(repo.branches)
branches = gitlab.execute('git branch')
branches = branches.replace(' ', '')
branches = branches.replace('*', '').split('\n')
print(branches)
print(len(branches))
cnt = 0
for b in branches:
    if b == 'master':
        continue
    gitlab.checkout(b)
    cnt += 1
    # 当前分支
    print("================当前进行中的分支 (%d)===============" % cnt)
    print(repo.active_branch)
    # git pull
    # repo.remote().pull()  # git pull -v origin
    gitlab.execute('git pull')
    try:
        gitlab.execute('git merge origin/master')
        gitlab.execute('git push origin '+b)
        # gitlab.execute('git push')
    except Exception as e:
        gitlab.execute('git merge --abort')
        conflict_branch.append(b)

print("===============conflict================")
print(conflict_branch)

运行情况如下:

运行结果

标签:execute,git,branches,python,gitlab,master,branch,print,分支
来源: https://blog.csdn.net/Yeva__/article/details/120448959