Skip to content

Instantly share code, notes, and snippets.

@makotoshimazu
Created August 6, 2020 11:35
Show Gist options
  • Select an option

  • Save makotoshimazu/12f55e6d1580a9f21d0ccfad8a1d4610 to your computer and use it in GitHub Desktop.

Select an option

Save makotoshimazu/12f55e6d1580a9f21d0ccfad8a1d4610 to your computer and use it in GitHub Desktop.

Revisions

  1. makotoshimazu created this gist Aug 6, 2020.
    33 changes: 33 additions & 0 deletions git-rm-untracked
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,33 @@
    #!/bin/zsh

    autoload -Uz colors
    colors

    echo " hash | branch"
    echo "--------+----------------------"
    git branch -vv | grep gone | sed -E 's/ +/ /g' | cut -d ' ' -f 2,3 |
    while read branch_name rev
    do
    #echo "branch: ${fg[green]}${branch_name}${reset_color} revision: ${fg[green]}${rev}${reset_color}"
    printf "${fg[green]}%-8s${reset_color}| %s\n" "${rev}" "${branch_name}"
    done
    echo ""

    echo -n "Are you okay to remove these branches? [y/N]: "
    read RESULT
    case $RESULT in
    [Yy])
    ;;
    *)
    exit 1
    ;;
    esac

    git branch -vv | grep gone | sed -E 's/ +/ /g' | cut -d ' ' -f 2,3 |
    while read branch_name rev
    do
    tag_name="archived__${branch_name}"
    git tag ${tag_name} ${rev}
    git branch -D ${branch_name}
    echo "Created a tag: ${tag_name} (${rev})"
    done