Skip to content

Instantly share code, notes, and snippets.

@zacdaryl
Last active March 22, 2019 07:58
Show Gist options
  • Save zacdaryl/2daef2c7bac3b01d9423c724b4b9f1fe to your computer and use it in GitHub Desktop.
Save zacdaryl/2daef2c7bac3b01d9423c724b4b9f1fe to your computer and use it in GitHub Desktop.

Revisions

  1. zacdaryl renamed this gist Mar 22, 2019. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  2. zacdaryl created this gist Mar 22, 2019.
    16 changes: 16 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,16 @@
    #!/bin/bash

    # Delete remote branches which have merged to master
    if [[ $1 == '-r' ]]; then
    git branch --all --merged remotes/origin/master | \
    grep --invert-match master | \
    grep --invert-match HEAD | \
    grep "remotes/origin/" | \
    cut -d "/" -f 3- | \
    xargs -n 1 git push --delete origin

    exit 0
    fi

    # Delete local branches which have merged to master
    git branch -d `git branch --merged | grep --invert-match master`