LoginSignup
4
4

More than 5 years have passed since last update.

爆速でリモートブランチにPushする

Last updated at Posted at 2016-09-27

したいこと

現在の作業中のローカルブランチを、同名のリモートブランチに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 です
4
4
0

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
4
4