-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathGit 删除多余的本地分支.bat
66 lines (61 loc) · 2.07 KB
/
Git 删除多余的本地分支.bat
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
@echo off
:: MoonLord 2022.01.10
:: 同级目录下存放 Git 工程文件夹,必须命名为工程名+分支名,不能包含空格
:: 根据文件夹后缀(-master、-develop、-release、-dev),判断当前是哪个分支
:: 无文件夹后缀,则默认为 master 分支
:: 删除多余的本地分支
:: 仅保留一个主要的分支
:: dir /AD /B >dir.txt
echo ---- > "%tmp%\branch.txt"
for /f usebackq %%i in ( `dir /AD /B` ) do (
echo "processing %%i ..."
cd "%%i"
echo "%%i" | findstr "\-\>" >nul || (
for /f usebackq %%j in ( `git branch` ) do (
echo "%%j" | findstr "* master\>" >nul || (
echo "branch to be deleted: %%j"
git branch -D "%%j"
)
)
)
echo "%%i" | findstr "\-master\>" >nul && (
for /f usebackq %%j in ( `git branch` ) do (
echo "%%j" | findstr "* master\>" >nul || (
echo "branch to be deleted: %%j"
git branch -D "%%j"
)
)
)
echo "%%i" | findstr "\-develop\>" >nul && (
for /f usebackq %%j in ( `git branch` ) do (
echo "%%j" | findstr "* develop\>" >nul || (
echo "branch to be deleted: %%j"
git branch -D "%%j"
)
)
)
echo "%%i" | findstr "\-release\>" >nul && (
for /f usebackq %%j in ( `git branch` ) do (
echo "%%j" | findstr "* release\>" >nul || (
echo "branch to be deleted: %%j"
git branch -D "%%j"
)
)
)
echo "%%i" | findstr "\-dev\>" >nul && (
for /f usebackq %%j in ( `git branch` ) do (
echo "%%j" | findstr "* dev\>" >nul || (
echo "branch to be deleted: %%j"
git branch -D "%%j"
)
)
)
echo %%i >> "%tmp%\branch.txt"
git branch >> "%tmp%\branch.txt"
echo ---- >> "%tmp%\branch.txt"
cd ../
)
echo "explorer.exe" "%tmp%\branch.txt"
"explorer.exe" "%tmp%\branch.txt"
pause
exit