Skip to content

Instantly share code, notes, and snippets.

@oyvholm
Created April 8, 2010 17:22
Show Gist options
  • Save oyvholm/360304 to your computer and use it in GitHub Desktop.
Save oyvholm/360304 to your computer and use it in GitHub Desktop.
#!/bin/sh
# git-eb
# File ID: 45c7afa2-434a-11df-8880-90e6ba3022ac
#
# Create new and unconnected branch
# usage: git eb <newbranch>
[ -z "$1" ] && { echo "usage: git eb <newbranch>" >&2; exit 1; }
[ -d ".git/." ] || { echo "git-eb: has to be executed from the top level of the tree" >&2; exit 1; }
[ -e ".git/refs/heads/$1" ] && { echo "git-eb: ref \"$1\" already exists" >&2; exit 1; }
git symbolic-ref HEAD refs/heads/"$1"
rm -f .git/index
git commit --allow-empty -m "Initial commit"
[alias]
# eb = empty, not connected branch
eb = "!sh -c 'git symbolic-ref HEAD refs/heads/\"$1\"; rm .git/index; git clean -fdx; git commit --allow-empty -m \"Initial commit\"' -"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment