Skip to content

Instantly share code, notes, and snippets.

@howardjp
Created February 6, 2010 17:34
Show Gist options
  • Save howardjp/296845 to your computer and use it in GitHub Desktop.
Save howardjp/296845 to your computer and use it in GitHub Desktop.
#!/bin/sh
#
# Script by Wesley J. Landaker <wjl@icecavern.net>
# posted to git@vger.kernel.org on 5 Feb 2010.
#
# Besides the error checking, this just creates a new ref
# and clears the index so you can start from a clean slate.
# No actual files are deleted from the work-tree.
if [ $# -ne 1 ]; then
2<&1
echo "usage: git emptybranch <new_branch>"
exit 1
fi
if ! git check-ref-format refs/heads/"$1"; then
2<&1
echo "fatal: '$1' is not a valid branch name."
exit 1
fi
git symbolic-ref -m "git emptybranch $1" HEAD refs/heads/"$1"
git rm --cached -r -q --ignore-unmatch -- '*'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment