Skip to content

Latest commit

 

History

History
54 lines (33 loc) · 1.55 KB

File metadata and controls

54 lines (33 loc) · 1.55 KB

⬅️ Back to Cleanup Branches Fast ⚡

⬆️ Previous Step: Delete Local Branches Whose Remote is Gone (PowerShell)

View and Clean Up Local Git Branches (Bash)

Category: Branch Management

Scripts to view and clean up local branches using Bash.

Examples

  • List local branches without a remote connection.
git branch -vv | grep -E '^\s*\S+\s+[^\[]+$' 
  • Delete local branches without remote tracking.
git branch -vv | grep -E '^\s*\S+\s+[^\[]+$' | awk '{print $1}' | xargs git branch -D 
  • List branches whose remote is gone.
git branch -vv | grep '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 'git branch -vv' to see tracking info for all branches.

Tip

Pipe to 'awk' and 'xargs' for batch deletion.

➡️ See the Next Step: View and Clean Up Local Git Branches (PowerShell)


Author: mike-rambil • Updated: 2024-06-10 • Tags: branches, cleanup, bash