Ubuntu: Bash prompt with Git branch

On several Git Video Tutorials people have these nice colored Git specific Bash prompts. When you are starting to work with Git, you realize that its really helpful to have the branch name around all the time. There easy and also many complex bash prompts out there, e.g. fully customizeable Git prompt scripts, one short scriptone script with functions or just a simple PS1 line.

I created one out of all of these. It shows a standard Ubuntu prompt on non Git directories, and an altered prompt inside git repositories. Inside a Git repository it shows the relative path to the Git’s root directory.

Git bash prompt

Git bash prompt

I created a Gish for it. Simple get it using curl and source it from your ~/.bashrc file:

curl https://gist.github.com/raw/4699573/git_bash_prompt.sh -o ~/.git_bash_prompt.sh
echo ". ~/.git_bash_prompt.sh" >> ~/.bashrc

Leave a Comment