目的
- 一回実行しただけで
$ git branch
コマンドで作成したブランチにスイッチするコマンドを登録する方法をメモ的にまとめる
方法
-
下記コマンドを実行して独自コマンドを登録するファイルを作成する。
$ vi ~/.bash_aliases
-
下記の内容を記載する。
~/.bash_aliasesfunction gbsw() { git branch $1; git switch $1; } alias gbsw=gbsw
-
下記コマンドを実行して.bash_profileのバックアップをとっておく。
$ cp ~/.bash_profile ~/.bash_profile_org
-
下記コマンドを実行して.bash_profileを開く。
$ vi ~/.bash_profile
-
下記の内容を追記する。
~/.bash_profilesource ~/.bash_aliases
-
下記コマンドを実行して変更を読み込む
$ source ~/.bash_profile
適当なローカルリポジトリでコマンド
$ gbsw ブランチ名
を実行して動作を確認する。-
問題なさそうなら下記コマンドを実行して.bash_profile_orgを削除する。
$ rm ~/.bash_profile_org