如何快速檢出多個git項目並刪除無用的本地分支

import os


def delete_not_master_branch():
    result = os.popen("git branch")
    git_branches = result.read()
    for git_branch in git_branches.splitlines():
        if git_branch != '* master':
            print(git_branch)
            os.system('git branch -d ' + git_branch)


def checkout_master_and_pull(file):
    # print(file)
    os.chdir(file)
    # os.system('dir')
    os.system('git checkout master')
    os.system('git pull')
    delete_not_master_branch()
    os.chdir('..')


files = os.listdir('.')
for file in files:
    if file.startswith('market'):
        checkout_master_and_pull(file)

腳本解釋:首先要將所有的項目放到一個目錄下

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章