githubのリポジトリでgh-pagesという名前のブランチを作ると、リポジトリ毎にwebページをホスティングしてくれる。
その時にgh-pagesブランチは親を持たないブランチにするのが定石なんだけど、いつもコマンドを忘れる。
ので、スクリプト書いた。
git-new-branch-without-parent
#!/bin/sh
#----------------------------------------
# git-new-branch-without-parent
#----------------------------------------
#
# make branch without parent
#
# example :
# git-new-branch-without-parent gh-pages
#
# @author ton1517 <tonton1517@gmail.com>
if [ $# -ne 1 ] || [ "$1" = "-h" ] || [ "$1" = "--help" ]; then
echo "usage: $0 <new-branch>"
exit
fi
branchName=$1
gitRootDir=`git rev-parse --show-toplevel`
if [ ! -n "$gitRootDir" ]; then
exit
fi
cd $gitRootDir
git symbolic-ref HEAD refs/heads/$branchName
rm .git/index
git clean -fdx
これを保存して、実行権限もたせて
chmod +x git-new-branch-without-parent
パスの通った場所に置いて、リポジトリ内で
git-new-branch-without-parent gh-pages
とやれば親を持たないgh-pagesブランチが作れる。
だいぶ楽になった。名前長い。