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)
腳本解釋:首先要將所有的項目放到一個目錄下