Skip to content

Instantly share code, notes, and snippets.

@frasertweedale
Created January 5, 2018 02:37
Show Gist options
  • Save frasertweedale/b01674f442c2c032b88a051ac62fc2c3 to your computer and use it in GitHub Desktop.
Save frasertweedale/b01674f442c2c032b88a051ac62fc2c3 to your computer and use it in GitHub Desktop.
Git: create an empty, orphan branch, in the background (e.g. gh-pages)
[ -z "$1" ] && echo "usage: $0 BRANCH_NAME" && exit 1
export GIT_INDEX_FILE=$PWD/.git/index-empty
REF=refs/heads/$1
git read-tree --empty
TREE=$(git write-tree)
COMMIT=$(git commit-tree "$TREE" -m "new empty orphan branch")
git update-ref "$REF" "$COMMIT"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment