-
Notifications
You must be signed in to change notification settings - Fork 2
git prompt (ブランチ名をプロンプトに表示)
cloudliner edited this page Oct 16, 2016
·
3 revisions
git-prompt
を導入すると、Git のブランチ名がプロンプトに常に表示されるようになるので、間違って master
に push
するといった事故が防げます。
導入後のコンソール表示イメージ
vagrant@enpit:~/ruthenium (master=) $
vagrant@enpit:~/ruthenium (master=) $ git checkout -b add_menu_images
vagrant@enpit:~/ruthenium (add_menu_images=) $
-
git-prompt.sh
をダウンロードして.git-prompt.sh
というファイル名でホームディレクトリに保存する
$ curl -o ~/.git-prompt.sh https://raw.githubusercontent.com/git/git/master/contrib/completion/git-prompt.sh
-
.git-prompt.sh
に実行権限をつける
$ chmod a+x ~/.git-prompt.sh
-
~/.bash_profile
を編集して次の行を追加して、プロンプトの表示を変更する
## Git
# Read script
source $HOME/.git-prompt.sh
# Show information to prompt
GIT_PS1_SHOWDIRTYSTATE=1
GIT_PS1_SHOWUPSTREAM=1
GIT_PS1_SHOWUNTRACKEDFILES=
GIT_PS1_SHOWSTASHSTATE=1
# Terminal
export PS1='\[\e]0;\u@\h: \w\a\]${debian_chroot:+($debian_chroot)}\u@\h:\w\[\033[1;30m\]$(__git_ps1)\[\033[0m\] \$'