Permalink
Browse files

Easy way to create an empty git branch.

I wanted to create some gh-pages on the train this morning and
couldn't remember the exact incantation off the top of my head, so I
wrote a tool to do it for me (relatively safely).
  • Loading branch information...
1 parent 0cfed61 commit 5fe65e2f5904599ca8676167b14b41d195791720 @dustin committed Jan 14, 2009
Showing with 29 additions and 0 deletions.
  1. +29 −0 git-emptybranch
View
@@ -0,0 +1,29 @@
+#!/bin/sh
+#
+# Create a new, empty branch in the current repo.
+#
+
+# Verify we're actually in a git repositoriy.
+git rev-parse --git-dir > /dev/null || exit 66
+
+# Ensure we have a branch name.
+if [ $# -ne 1 ]
+then
+ echo "What do you want to call this branch?"
+ exit 64
+fi
+
+refname=refs/heads/$1
+
+# Let's not clobber an existing branch.
+if git rev-parse --verify -q $refname > /dev/null
+then
+ echo "$refname already exists."
+ exit 65
+fi
+
+# Do the work.
+git symbolic-ref -m "Creating an empty branch" HEAD $refname \
+ || exit $?
+rm .git/index || exit $?
+git clean -df || exit $?

0 comments on commit 5fe65e2

Please sign in to comment.