0
0

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.

ターミナルにGitのブランチ名を載せる

0
Last updated at Posted at 2019-04-04

gitのブランチ名をいちいちコマンド打って確認するのはめんどくさい.そこでターミナルにGitのブランチ名を以下のように常時表示させる方法を紹介します.

スクリーンショット 2019-04-04 23.28.01.png

使用環境

  • MacBook Pro (13-inch, 2017, Two Thunderbolt 3 ports)

brewでbash-completionをインストールする

以下のコマンドを打ってbash-completionをインストールします.

$ brew install git bash-completion

~/.bashrcの編集

以下のように~/.bashrcを変更します.

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

ここまでできたら,あとは変更を反映させるのみです.

$ source ~/.bashrc

~/.bash_profile

以上でブランチ名が表示されると思うのですが,このままだとターミナルを開けるごとにsourceコマンドを打たなければいけません.それはめんどくさいので,~/.bash_profileも変更してしまいましょう.

~/.bash_profile
.
.
.
# 末尾に追加
test -r ~/.bashrc && . ~/.bashrc

こうすることでターミナルを新しく開けたとしてもブランチ名が付いていると思います.

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?