X-Git-Url: https://oss.titaniummirror.com/gitweb?p=git-utils.git;a=blobdiff_plain;f=git-empty-branch;fp=git-empty-branch;h=75e90ff0d1b3a2542afeeeecb9cc78dc4922a7e4;hp=0000000000000000000000000000000000000000;hb=5294df37a0c3bbbc4c1fd0baf3a9335c3802b108;hpb=55a175be6e79ac7ce6cf96f94422806f05bb8c60 diff --git a/git-empty-branch b/git-empty-branch new file mode 100755 index 0000000..75e90ff --- /dev/null +++ b/git-empty-branch @@ -0,0 +1,26 @@ +#!/bin/sh +# git-empty-branch [branch] + +if [ $# -eq 1 ]; then + branch=$1 +else + echo "Usage: $0 [branch]" >&2 + exit 1 +fi + +if [ -n "$(git show-ref --heads $branch)" ]; then + echo "branch already exists" >&2 + exit 1 +fi + +git symbolic-ref HEAD refs/heads/$branch && \ + rm .git/index && git clean -fdx && \ + echo "Now on empty branch $branch" || \ + fail +exit 0 + +fail() +{ + echo "Branch failure. You may need to git reset --hard" >&2 + exit 1 +}