Why doesn't my bash prompt update?

I’m new to git and I’m trying to add the current git branch to my already existing prompt, which is defined as follows :

SELECT="if [ \$? = 0 ]; then echo \"${SMILEY}\"; else echo \"${FROWNY}\"; fi"

export PS1="${RESET}${YELLOW}\u@\h${NORMAL} \`${SELECT}\` ${YELLOW}\w $(__git_ps1) >${NORMAL} "

I tried it (by sourcing my .bashrc file again) and it seemed to work, but then I went on another branch and it did not update. How can I make sure the $(__git_ps1) is not cached?

  • Git Autocompletion looks weird (and only half-functional)
  • How to set TERM environment variable in Windows so that it works with Bash via SSH and locally with Git?
  • Confusing error from | xargs sed
  • git alias with bash conditional logic comparing strings - syntax issues
  • Why does git rev-list fail to detect remote / origin changes?
  • Git: Permission Denied when Opening Text Editor
  • EGit + Beanstalk - Auth Fail
  • How do I configure git on a nitrous io box to deploy to AWS Elastic Beanstalk?
  • Commit with case-change is being ignored
  • Best practice for three environment setup - to avoid pushing things live when not ready yet
  • repo merge between different Android Repository
  • Git repository broken after computer died
  • 2 Solutions collect form web for “Why doesn't my bash prompt update?”

    You need a backslash on the $ so it isn’t expanded immediately. (Compare to the `...`, which is a different way of writing $(...).)

    export PS1="${RESET}${YELLOW}\u@\h${NORMAL} \`${SELECT}\` ${YELLOW}\w \$(__git_ps1) >${NORMAL} "

    I would agree with @MikeSep about using single quotes, but it’s actually a bit more optimal to let the colors and such be substituted immediately. Not necessary, just somewhat better. That said, it is easier to understand what’s going on if you use the single quotes.

    Your PS1 string is probably getting evaluated before it is getting saved, but you really want the __git_ps1 command to run each time you get a command prompt. I’d recommend using single quotes instead of double quotes for your export PS1='${RESET}...' line.

    Git Baby is a git and github fan, let's start git clone.