LoginSignup
10
10

More than 5 years have passed since last update.

毎回gh-pagesブランチを作る時のコマンドを忘れる

Posted at

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ブランチが作れる。

だいぶ楽になった。名前長い。

10
10
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
10
10