LoginSignup
0
0

More than 1 year has passed since last update.

Mac Git ブランチを作成してそのブランチにスイッチする独自コマンドを登録する

Posted at

目的

  • 一回実行しただけで$ git branchコマンドで作成したブランチにスイッチするコマンドを登録する方法をメモ的にまとめる

方法

  1. 下記コマンドを実行して独自コマンドを登録するファイルを作成する。

    $ vi ~/.bash_aliases
    
  2. 下記の内容を記載する。

    ~/.bash_aliases
    function gbsw() {
        git branch $1;
        git switch $1;
    }
    alias gbsw=gbsw
    
  3. 下記コマンドを実行して.bash_profileのバックアップをとっておく。

    $ cp ~/.bash_profile ~/.bash_profile_org
    
  4. 下記コマンドを実行して.bash_profileを開く。

    $ vi ~/.bash_profile
    
  5. 下記の内容を追記する。

    ~/.bash_profile
    source ~/.bash_aliases
    
  6. 下記コマンドを実行して変更を読み込む

    $ source ~/.bash_profile
    
  7. 適当なローカルリポジトリでコマンド$ gbsw ブランチ名を実行して動作を確認する。

  8. 問題なさそうなら下記コマンドを実行して.bash_profile_orgを削除する。

    $ rm ~/.bash_profile_org
    
0
0
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
0
0