Mar 11, 2013

Showing the current Git branch in a shell prompt

The following commands in ~/.bash_profile will show you on what Git branch you are and if there are dirty files there:

source /opt/local/share/doc/git-core/contrib/completion/git-completion.bash
source /opt/local/share/git-core/git-prompt.sh
GIT_PS1_SHOWDIRTYSTATE=true
export PS1='\h:\w \[\033[1;36m\]$(__git_ps1 "[%s] ")\[\033[1;37m\]\$ '

This will show the branch in the cyan color and only in the directory, where you checked out the project. If there are dirty files, it will show an asterisk after the branch name.

Example:

Atlas:~/Projects/TYPO3/TYPO3_6-0 [issue_46000 *] $

No comments:

Post a Comment