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)
运行情况如下: