]> oss.titaniummirror.com Git - git-utils.git/blobdiff - git-empty-branch
Add a command to create an empty git branch.
[git-utils.git] / git-empty-branch
diff --git a/git-empty-branch b/git-empty-branch
new file mode 100755 (executable)
index 0000000..75e90ff
--- /dev/null
@@ -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
+}