]> oss.titaniummirror.com Git - git-utils.git/commitdiff
Add a command to create an empty git branch.
authorsmckown <smckown@986fd584-583e-0410-b54d-b9fe63dff8e5>
Wed, 9 Dec 2009 18:09:35 +0000 (18:09 +0000)
committersmckown <smckown@986fd584-583e-0410-b54d-b9fe63dff8e5>
Wed, 9 Dec 2009 18:09:35 +0000 (18:09 +0000)
I find that I use this all the time.

git-empty-branch [new file with mode: 0755]
git-empty-branch.1 [new file with mode: 0644]

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
+}
diff --git a/git-empty-branch.1 b/git-empty-branch.1
new file mode 100644 (file)
index 0000000..a78daec
--- /dev/null
@@ -0,0 +1,22 @@
+.\"
+.TH "git-empty-branch"
+.SH NAME
+git-empty-branch \- create a new empty branch in the local repository
+
+.SH SYNOPSIS
+\fBgit-empty-branch\fR [\fIBRANCH\fR]
+
+.SH "DESCRIPTION"
+
+.PP
+\fBgit-empty-branch\fR creates a new empty branch in the local repository.
+\fIBRANCH\fR must not already exist.
+
+.SH "OPTIONS"
+
+.TP
+\fIBRANCH\fR
+The name to assign the new empty branch.
+
+.SH "SEE ALSO"
+git-branch(1)