Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
Community
OrganizationAdvent CalendarQiitadon (β)
Service
Qiita JobsQiita ZineQiita Blog
2
Help us understand the problem. What is going on with this article?
@mokkos

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

More than 1 year has passed since last update.

事前準備

$ 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
Help us understand the problem. What is going on with this article?
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
mokkos

Comments

No comments
Sign up for free and join this conversation.
Sign Up
If you already have a Qiita account Login
2
Help us understand the problem. What is going on with this article?