See Your Current Git Branch In Your Shell Prompt – In Full, Glorious Color!

Here’s a cool bit of code that displays your current git branch in your shell prompt. Like this:


Pretty handy. Here’s all you have to do to get this beauty working for you. In your .bash_profile (or .bashrc ) file, add this:

function parse_git_branch_and_add_brackets { git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/\ \[\1\]/' }
PS1="\h:\W \u\[\033[0;32m\]\$(parse_git_branch_and_add_brackets) \[\033[0m\]\$ "

Once added, you’ll see your current working branch in your shell prompt automatically. ┬áSuper handy and may even save you a bit of time.

Not commented yet.