Do you want your shell prompt to help you with knowing what is going on in your git repository? You can do that pretty easily. There are a number of people who have done some really wild things, from simply showing what branch you are in, to showing the name of the repository, and if you are the middle of an operation (such as a rebase, merge, etc.).

zsh

Check out this fancy prompt for zsh:

You can do that by grabbing the 60_prompt and putting it into your .zshenv, but I prefer to separate the different pieces of my shell environment, so I do the following:

  1. mkdir .zsh
  2. cd .zsh
  3. wget the 60_prompt
  4. add the following to your .zshrc
    for zshrc_snipplet in ~/.zsh/[0-9][0-9][^.]#; do
        source $zshrc_snipplet
    done

Here is another way to do this in zsh, without all the fancy colors, and less functionality.

And yet another one that is able to detect what revision control system you are using and make sure you are aware of that.

bash

Make sure your colors are defined, by also adding the following into your .bashrc:

# \e[XX;Ym
# 3X for foreground, 4X for background
# 0:black,1:red,2:green,3:yellow,4:blue,5:magenta,6:cyan,7:white
# ;0/;1 for regular/bold
# \[...\] needed to tell bash to ignore in calculating length
prompt_c_grey='\[\e[30;1m\]'
prompt_c_green='\[\e[32;1m\]'
prompt_c_yellow='\[\e[33;1m\]'
prompt_c_blue='\[\e[34;1m\]'
prompt_c_magenta='\[\e[35;1m\]'
prompt_c_cyan='\[\e[36;1m\]'
prompt_c_reset='\[\e[0m\]'

Then get this function defined in your .bashrc:

function prompt_string {
    # previous command return code
    local rc=${1:-$?}
    printf '%s' $prompt_c_green
    # add username to prompt if it doesn't match ME
    if [ "$USER" != "$ME" ] ; then
        printf '\u@'
    fi
    # add hostname
    printf "\h"
    # separator
    printf '%s:' $prompt_c_grey
    # add path
    printf '%s\w' $prompt_c_blue
    # add git info
    if true ; then
        printf ' %s[' $prompt_c_grey
        git status 2>/dev/null | \
          while read -r line; do
            local c=$((c+1))
            if ((c == 1)); then
                if [[ "$line" =~ ^'# Not currently on any branch.' ]] ; then
                    local branch='(none)'
                else
                    local branch=$(echo $line | awk '{ print $4 }')
                fi
                printf '%s%s' $prompt_c_yellow $branch
            elif [[ "$line" =~ ^'# Unmerged paths:' ]] ; then
                printf '%s!' $prompt_c_cyan
            elif [[ "$line" =~ ^'# Changes to be committed:' ]] ; then
                printf '%s~' $prompt_c_cyan
            elif [[ "$line" =~ ^'# Changed but not updated:' ]] ; then
                printf '%s*' $prompt_c_cyan
            fi
        done
        printf '%s]' $prompt_c_grey
    fi
    # add return code and close
    printf ' %s%s\$%s ' $prompt_c_grey $rc $prompt_c_reset
}

Then you can set your prompt by doing the following:

PROMPT_COMMAND=prompt_command
prompt_command() { PS1=$(prompt_string $?); }

Here is another mechanism to do all of this in bash.