LoginSignup
2
2

More than 5 years have passed since last update.

Mac のターミナルで Git のブランチ名を表示する手順

Last updated at Posted at 2018-05-04

事前準備

$ git version

Git のバージョンを確認し、Apple git の場合は、homebrew の git にアップデートしておく。

$ brew install git

 gitcomprication.bash を移動する

gitcomprication.bash を 指定のディレクトリに移動する。

$ mkdir -p /usr/local/git/contrib/completion/
$ cd usr/local/Cellar/git/{gitのversionの数字}/etc/bash_completion.d
$ mv git-completion.bash /usr/local/git/contrib/completion/

 ~/.bashrc に設定する

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

 ~/.bashrc を反映させる

$ source ~/.bashrc

※-bash: __git_ps1: command not found エラーが出た場合

# git-completion.bash の前に追加で git-prompt.sh を読み込ませる
source /usr/local/etc/bash_completion.d/git-prompt.sh
source /usr/local/etc/bash_completion.d/git-completion.bash

この手順でGit のブランチ名が出るようになりました\( ^0^ )/

参考

http://38ch.hateblo.jp/entry/2017/02/12/180145
https://sue445.hatenablog.com/entry/2012/08/30/005627

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