Skip to content

Instantly share code, notes, and snippets.

@qs-wang
Forked from TBonnin/git-remove-branches
Created June 25, 2020 14:34
Show Gist options
  • Select an option

  • Save qs-wang/f5a7c302a39c2ad12696f9c47dbeb3b6 to your computer and use it in GitHub Desktop.

Select an option

Save qs-wang/f5a7c302a39c2ad12696f9c47dbeb3b6 to your computer and use it in GitHub Desktop.

Revisions

  1. @TBonnin TBonnin revised this gist Apr 1, 2014. 1 changed file with 3 additions and 0 deletions.
    3 changes: 3 additions & 0 deletions git-remove-branches
    Original file line number Diff line number Diff line change
    @@ -23,3 +23,6 @@ then
    echo "Done!"
    say "Obsolete branches are removed"
    fi

    echo "Please, tell your teammates to run 'git remote prune origin' command in order to clean their local repository"

  2. @TBonnin TBonnin created this gist Nov 12, 2012.
    25 changes: 25 additions & 0 deletions git-remove-branches
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,25 @@
    #!/bin/bash

    # This has to be run from master
    git checkout master

    # Update our list of remotes
    git fetch
    git remote prune origin

    # Remove local fully merged branches
    git branch --merged master | grep -v 'master$' | xargs git branch -d

    # Show remote fully merged branches
    echo "The following remote branches are fully merged and will be removed:"
    git branch -r --merged master | sed 's/ *origin\///' | grep -v 'master$'

    read -p "Continue (y/n)? "
    if [ "$REPLY" == "y" ]
    then
    # Remove remote fully merged branches
    git branch -r --merged master | sed 's/ *origin\///' \
    | grep -v 'master$' | xargs -I% git push origin :%
    echo "Done!"
    say "Obsolete branches are removed"
    fi