11
9

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

ターミナル操作:今いるブランチ名を表示させよう

Last updated at Posted at 2020-03-13

レクチャー動画で良く見るこれ

今いるディレクトリ横に、現在のブランチ名が表示されてる!
なんて便利なんだー!
これがあれば、わざわざ
git branch
して、確認せずに済むではないかー!

スクリーンショット 2020-03-13 15.10.10.png

てこでやり方をまとめてみました!!

Mac標準のgitを使ってない?

which git
出力 /usr/local/bin/git

これ以外の出力になっていると、標準Macのgitの可能性あり。

Homebrewでインストールできてる?

brew list
出力 git

Homebrewでインストールする最新verのgitが必要。
上記コマンドで出力されない人は、Homebrewで最新verのgitをインストールしよう!

git --version
出力 現在のgitのver

ちなみに現在2020/3/14では、git version 2.25.1でした。

Homebrewでgitをインストール

brew install git

少し時間かかります。
この時、インストール先が表示されるので覚えておきます!
スクリーンショット 2020-03-13 14.15.29.png
私のインストール先は、/usr/local/Cellar/git

PATHを通す

sudo vi ~/.bash_profile
ここを編集。最後の行に追加しましょう。以下を↓

PATH=/usr/local/Cellar/git:$PATH
export PATH

source ~/.bash_profile
ファイルの内容を更新。これをしないと反映されないです。

which git
出力 /usr/local/bin/git

これになっているはず。

いよいよ仕上げ!

sudo vi ~/.bashrc

を開いて、ブランチ名をターミナルでも表示させる設定を記述。

source /usr/local/etc/bash_completion.d/git-prompt.sh
source /usr/local/etc/bash_completion.d/git-completion.bash
GIT_PS1_SHOWDIRTYSTATE=true
export PS1='\[\033[32m\]\u@\h\[\033[00m\]:\[\033[34m\]\w\[\033[31m\]$(__git_ps1)\[\033[00m\]\$ '

source ~/.bashrc
ファイル内容を更新。

スクリーンショット 2020-03-13 15.10.10.png こんな感じで、今いるディレクトリの横に所属しているブランチ名が表示されるはず!
11
9
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
11
9

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?