Skip to content

Instantly share code, notes, and snippets.

@dhbradshaw
Created February 28, 2022 15:45
Show Gist options
  • Save dhbradshaw/d1c51f251c6e5ed1ff3ecd07c7676a17 to your computer and use it in GitHub Desktop.
Save dhbradshaw/d1c51f251c6e5ed1ff3ecd07c7676a17 to your computer and use it in GitHub Desktop.

Revisions

  1. dhbradshaw created this gist Feb 28, 2022.
    9 changes: 9 additions & 0 deletions safe--git-branch-delete.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,9 @@
    # Delete all redundant git branches

    # 1. `git branch` lists all the branches
    # 2. `xargs -L1` consumes the pipe output one line at a time, feeding it as an an arg to the target command
    # 3. `git branch -d` deletes the branches that are redundant (already merged).
    # Note: this print results for each branch, either
    # saying it's deleted or that you need to use -D to delete it because it's not redundant.

    git branch | xargs -L1 git branch -d