Skip to content

Instantly share code, notes, and snippets.

@smudge
Last active January 26, 2022 16:08

Revisions

  1. smudge revised this gist Jan 26, 2022. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion delete_remote_git_branches.sh
    Original file line number Diff line number Diff line change
    @@ -5,7 +5,7 @@
    # This is REALLY UNSAFE. Don't do this on a shared repo!
    # Again: DO NOT DO THIS unless you're really, really sure.

    git branch -r | grep -e "origin" | grep -v "origin/master" | awk '{sub(/origin\//,"");print}'| sed 's/^[ *]*//' | sed 's/^/git push origin :/' | bash
    git branch -r | grep -e "origin" | grep -v "origin/main" | awk '{sub(/origin\//,"");print}'| sed 's/^[ *]*//' | sed 's/^/git push origin :/' | bash

    ### BONUS: Delete all remote tags
    # Same warning applies!
  2. smudge revised this gist Apr 25, 2019. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion delete_remote_git_branches.sh
    Original file line number Diff line number Diff line change
    @@ -5,7 +5,7 @@
    # This is REALLY UNSAFE. Don't do this on a shared repo!
    # Again: DO NOT DO THIS unless you're really, really sure.

    git branch -r | grep -v "origin/master" | awk '{sub(/origin\//,"");print}'| sed 's/^[ *]*//' | sed 's/^/git push origin :/' | bash
    git branch -r | grep -e "origin" | grep -v "origin/master" | awk '{sub(/origin\//,"");print}'| sed 's/^[ *]*//' | sed 's/^/git push origin :/' | bash

    ### BONUS: Delete all remote tags
    # Same warning applies!
  3. smudge revised this gist Nov 1, 2017. 1 changed file with 5 additions and 1 deletion.
    6 changes: 5 additions & 1 deletion delete_remote_git_branches.sh
    Original file line number Diff line number Diff line change
    @@ -9,5 +9,9 @@ git branch -r | grep -v "origin/master" | awk '{sub(/origin\//,"");print}'| sed

    ### BONUS: Delete all remote tags
    # Same warning applies!
    # Deletes 1000 at a time

    git tag -l | xargs -n 1 git push --delete origin
    git push origin --delete $(git ls-remote --tags origin | grep -v "{}$" | awk '{sub(/.+refs\/tags\//,"");print}' | head -n 1000)

    # Delete all local tags:
    git tag -l | xargs git tag -d
  4. smudge created this gist Nov 1, 2017.
    13 changes: 13 additions & 0 deletions delete_remote_git_branches.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,13 @@
    #### Delete all remote git branches
    # Primary purpose: When you fork a repo and want a clean slate for your fork.

    #### WARNING
    # This is REALLY UNSAFE. Don't do this on a shared repo!
    # Again: DO NOT DO THIS unless you're really, really sure.

    git branch -r | grep -v "origin/master" | awk '{sub(/origin\//,"");print}'| sed 's/^[ *]*//' | sed 's/^/git push origin :/' | bash

    ### BONUS: Delete all remote tags
    # Same warning applies!

    git tag -l | xargs -n 1 git push --delete origin