LoginSignup
2
1

More than 3 years have passed since last update.

【Bash】ターミナル上で今いるgitのブランチ名を常に表示する

Last updated at Posted at 2020-05-28

やりたいこと

スクリーンショット 2020-05-28 23.52.52.png

ローカルリポジトリで開発中、ちょくちょく今いるブランチを間違えてコミットしてぐちゃぐちゃになることがありました。ずっとターミナルにカレントブランチ表示してたら間違えないだろうと言うことでやり方を調べました。

環境(念のため)

Mac
Bash
ターミナル

手順

1.https://github.com/git/git/blob/master/contrib/completion/git-prompt.sh にアクセスしてソースをダウンロード(Rawボタン右クリック、ファイルを保存)

ダウンロードフォルダにあるファイルを以下コマンドで移動。

cp /Users/<ユーザ名>/Downloads/git-prompt.sh /usr/local/etc/bash_completion.d/git-prompt.sh

2.bash_profileに以下を追記

vi ~/.bash_profile
#show git branch
source /usr/local/etc/bash_completion.d/git-prompt.sh
GIT_PS1_SHOWDIRTYSTATE=true
export PS1='[\u@\h: $(__git_ps1 "(%s)")\W]\$ '

以上でカレントブランチが表示されるようになります!

ありがとうございました。

2
1
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
2
1