(Linux用) gitのbranchの情報をプロンプトに出す方法メモ

  1. git-prompt.shをダウンロード

    wget https://raw.github.com/git/git/master/contrib/completion/git-prompt.sh

  2. .bashrcを編集する

    1. PS1を設定している箇所を変更。最後の\$の前に$(__git_ps1 " (%s)")を入れる
      PS1='${debian_chroot:+($debian_chroot)}[\033[01;32m]\u@\h[\033[00m]:[\033[01;34m]\w[\033[00m]$(__git_ps1 " (%s)")\$ '
      debian 10での設定
    2. 末尾にダウンロードしたgit-prompt.shの読み込みを追加(PS1の設定の後でも動作するらしい)
      source /path/to/git-prompt.sh

これでOKのはず

参考サイト: git :: bash プロンプトにブランチ名と作業ツリーの状態を表示する [Tipsというかメモ]