Files
Advanced-Git/contents/view-and-clean-up-local-git-branches-powershell.md
2025-07-26 07:49:48 +00:00

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)

Category: Branch Management

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

  1. List local branches.
  2. Delete local branches without remote.
  3. View branches with deleted remote.
  4. 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