Where exactly Git Bash for Windows' prompt is defined?
Both my office and home computers have Git Bash for Windows from the very same source (Git for Windows, that came with TortoiseGit), but Git Bash’s prompt differs on both machines:
- on office computer I have
/c/path (branch)all green (this is, how I would like it to have),
- on home computer I have only path (no branch) and all white.
Up until now I was told, that this is
PS1 variable, kept in
~/.bashrc file. However, on both machines, this files is missing (executing
notepad ~/.bashrc opens up empty Notepad).
I’m lost here. If
~/.bashrc doesn’t exists, then from where Git Bash “knows”, that it should display current branch, in a green prompt? And why the same doesn’t happen on second machine?
EDIT: I also tried to compare
c:\Program Files\Git\etc\ folder contents for both machines and contents of
Git Bash.vbs file. There identical on both computers so I even more have no idea, how it can be, that Git Bash’s prompt differs on both computers (and how to fix this).
Several answers (like this, this and this) has suggested me, that I should look for
.bash_prompt files. Unfortunately, these two also are missing on both my computers.
Exactly what file decides about that under Windows 7? Where else should I look for, and what
PS1 variable’s value should be, to have current branch shown in green prompt on both machines?
2 Solutions collect form web for “Where exactly Git Bash for Windows' prompt is defined?”
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.
/etc/profile script in line #156 in my version, you see the
PS1 command being set and using
$PS1 as a means of executing an external command in the prompt. (A third way I didn’t mention previously).
__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 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
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
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.
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