I found it helpful to see the Github branch I am working on in the Bash prompt.
Adding the following snippet into the .bashrc
allows for a colored bash prompt that parses and includes the git branch and whether there are uncommitted changes in the directory. Uncommitted changes are specified by the inclusion of a *
after the git branch. For larger git branches, tracking file modification may be slow. Comment the MODIFIED
line to not check for uncommitted file modifications.
Add this snippet to your .bashrc
:
parse_git_branch() {
MODIFIED=$(git status 2> /dev/null | grep 'Changes not staged for commit' >/dev/null && echo \*)
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ (\1'"$MODIFIED"')/'
}
export PS1='\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[33m\]$(parse_git_branch)\[\033[00m\]$ '