mirror of
https://github.com/mike-rambil/Advanced-Git.git
synced 2025-12-20 09:00:43 -06:00
1.6 KiB
1.6 KiB
⬅️ Back to Cleanup Branches Fast ⚡
⬆️ Previous Step: View and Clean Up Local Git Branches (Bash)
View and Clean Up Local Git Branches (PowerShell)
Scripts to view and clean up local branches using PowerShell.
Examples
- List local branches without a remote connection.
git branch -vv | Select-String -NotMatch "origin/"
- Delete local branches without remote tracking.
git branch -vv | Select-String -NotMatch "origin/" | ForEach-Object { $branch = ($_ -split "\s+")[1]; git branch -D $branch }
- List branches whose remote is gone.
git branch -vv | Select-String 'gone'
Steps
- List local branches.
- Delete local branches without remote.
- View branches with deleted remote.
- Delete stale local branches.
Warnings
- ⚠️ Deleting branches is irreversible. Double-check before running destructive commands.
ProTips
Tip
Use PowerShell's 'Select-String' for flexible filtering.
Tip
Automate cleanup with a script for regular maintenance.
➡️ Continue to Next Topic: Git Command Reference (Full List)
Author: mike-rambil • Updated: 2024-06-10 • Tags: branches, cleanup, powershell