-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgit-prune.ps1
More file actions
24 lines (19 loc) · 895 Bytes
/
git-prune.ps1
File metadata and controls
24 lines (19 loc) · 895 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
Param
(
[Parameter(Mandatory = $false)][switch]$remote
)
# garbage collect
git gc --aggressive
# update local list of pruned branches on the remote to local:
git fetch --prune
if ($remote.IsPresent) {
# delete branches on remote origin that have been merge to master
git branch --merged remotes/origin/master -r | %{$_.trim().replace('origin/', '')} | ?{$_ -notmatch 'master'} | ?{$_ -notmatch 'develop'} | ?{$_ -notmatch 'release/*'} | %{ "delete remote $_"; git push --delete origin $_ }
} else {
# delete local branches that have been merged to master
git branch --merged remotes/origin/master | %{$_.trim()} | ?{$_ -notmatch 'master'} | ?{$_ -notmatch 'develop'} | ?{$_ -notmatch 'release/*'} | %{ "delete local $_"; git branch -d $_ }
}
# remove stale refs (local refs to branches that are gone on the remote)
git remote prune origin
# garbage collect
git gc --aggressive