Skip to content

Instantly share code, notes, and snippets.

@nickolasburr
Created June 6, 2017 15:54
Show Gist options
  • Save nickolasburr/c7398d8f4d12ed1f5f7af3f314780ab8 to your computer and use it in GitHub Desktop.
Save nickolasburr/c7398d8f4d12ed1f5f7af3f314780ab8 to your computer and use it in GitHub Desktop.

Revisions

  1. nickolasburr created this gist Jun 6, 2017.
    31 changes: 31 additions & 0 deletions clip.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,31 @@
    #!/usr/bin/env bash

    # clip: Delete local branch, with option to force delete unmerged branches
    clip () {
    # return if we're not inside an actual work tree
    if [[ ! "$(git rev-parse --is-inside-work-tree)" ]] 2>/dev/null; then
    echo "fatal: Not a git repository (or any of the parent directories): .git"
    return 1
    fi

    # if no arguments were given to `clip`, notify the user and return
    if [[ $# -eq 0 ]]; then
    echo "Usage: clip [-f|--force] BRANCHREF"
    return 1
    fi

    # wrangle the given flag options
    while [[ $# -gt 0 ]]; do
    case "$1" in
    -f|--force)
    shift
    git branch -D "$1"
    break
    ;;
    *)
    git branch -d "$1"
    break
    ;;
    esac
    done
    }