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?

  • How do I checkout a sub direcotry in a huge git repo with specified branch and with sparse checkout?
  • Git filter-branch, variables, and bash
  • How to open all modified files with git?
  • How to create alias for git bash to make fast cd through directories
  • Unable to install the latest version of Gitlab
  • Can not activate a virtualenv in GIT bash mingw32 for Windows
  • git stash pop: avoiding stash drop and un-staging steps
  • What is the difference between github and gist?
  • I accidentally created a git local branch called --track, how can I delete it?
  • Could Not Resolve Host github.com
  • How to update git submodule who's history was rewritten
  • Best practice to edit make changes to old commits with git
  • 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.