Where exactly Git Bash for Windows' prompt is defined?

I would make a comment if I would have enough reputation,

but my guess is that the bashrc is not in your homefolder: ~/ but in the all users or general user folder(I dont know how it is named exactly). Look under your users where all users are located and search for .bashrc.

Look here : C:\Users\All Users or: C:\Users\Default User


Git on Windows almost always uses a bash shell. So, it's not Git setting the prompt as much as Bash does.

There are two ways to set prompts in Bash. One is the PS1 command which is fairly flexible, but is limited to a particular set of escape character sequences. Unfortunately, Git information isn't one of those escape sequences (although I suspect it'll come someday). You can use the second way to set the prompt by setting the PROMPT_COMMAND environment variable. If this is set, the $PROMPT_COMMAND is executed and used as the prompt instead of the PS1 environment variable.

When you install the standard Git with BASH, you're Git prompt is defined under the /etc/profile file. By the way, etc is a directory under where you've installed Git which is usually under %PROGRAMFILES% unless you changed it when you installed Git.

Under the /etc/profile script in line #156 in my version, you see the PS1 command being set and using $(__git_ps1) in $PS1 as a means of executing an external command in the prompt. (A third way I didn't mention previously).

The __git_ps1 is a shell function. You'll also notice a bit above (line #154 in my version) that /etc/git-completion.bash is being sourced in as well as /etc/git-prompt.sh. It's /etc/git-prompt.sh that defines the __git_ps1 function (Line #273 in my version) is defined. You'll notice that the __git_ps1 function pulls in several other functions defined in /etc/git-prompt.sh.

So, in a very Rube Goldberg manner, the Git prompt is being defined in /etc/profile via defining $PS1 which pulls in /etc/git-prompt.sh which defines a __git_ps1 function that pulls in the __git_ps1_show_upstream function and the __git_ps1_colorize_gitstring function. Then, $PS1 uses the $(...) string as part of pulling in the __git_ps1 function into PS1.

You can define your own $HOME/.bash_profile to override the way the prompt is set to define your own prompt. And, when you do that, you can also use the __git_ps1 Bash function in your own prompt.

Or, you can simply decide not to touch anything, and just back away very slowly. After all, you may have actual work to do.


On my Windows10, "__git_ps1" is defined in: C:/Program Files/Git/etc/profile.d/git-prompt.sh


I faced similar issue and realized that accidently I had added ${HOME} variable under environment/system variables(This PC) in my windows 10 64 bit pointing to my unixhome path. Once I removed it, the issue got fixed. My Git Bash prompt is back to how it used to look.