Natterings RSS

Mobile Hacker Stephen Ryner Jr. is also known as @nuthatch

Archive

May
15th
Sat
permalink

Add git branch to bash prompt

I’ve had this on my work laptop for over a year, but never got around to adding it to my home machine.

Edit your .profile to add these:

function parse_git_branch{
ref=$(git symbolic-ref HEAD 2> /dev/null) || return
echo "("${ref#refs/heads/}")"
}
# path prompt
export PS1="\w \$(parse_git_branch)\$ "


Now your prompt will look like this if you’re inside a git repository:

~/projects/iPhone/UIKit-Artwork-Extractor (master)$ 


Branches are cheap in git, and this will help you remember which one you’re on.

  1. nuthatch posted this
blog comments powered by Disqus