したいこと
現在の作業中のローカルブランチを、同名のリモートブランチにPushしたい
そんなスクリプトを作ったので紹介させていただきます。
シェル
bashrcに追記する
function gp(){
current_branch_name=`git rev-parse --abbrev-ref HEAD`
if [ "${current_branch_name}" != 'develop' ] && [ "${current_branch_name}" != 'master' ]; then
git push origin ${current_branch_name}
else
echo "このブランチは ${current_branch_name} です"
fi
}
使い方
コンソールでgp
と叩くとgit push origin 現在のブランチ名
となります
コンソール
# some_branchブランチで作業中のとき
$ gp
Counting objects: 7, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (6/6), done.
Writing objects: 100% (7/7), 9.31 KiB | 0 bytes/s, done.
Total 7 (delta 1), reused 0 (delta 0)
To https://s1160054@bitbucket.org/s1160054/workplace.git
178accd..d626f83 some_branch -> some_branch
develop, masterブランチにはPushしない
コンソール
# masterブランチの時
$ gp
=> このブランチは master です
コンソール
# developブランチの時
$ gp
=> このブランチは develop です