Alter Git prompt on Windows
The default git-completion script supports part of what you are after. If you set GIT_PS1_SHOWUPSTREAM="verbose git" in the /etc/profile file then it will add the number of commits ahead of your upstream branch into the prompt. You may need to set the prompt as below to include a (%s)
in the git specific part:
export PS1='\[\033]0;$MSYSTEM:\w\007\033[32m\]\u@\h \[\033[33m\w$(__git_ps1 " (%s)")\033[0m\]\$ '
For the time part - thats new to me. But the git-bash should handle any unix version you may have found. Just edit /etc/profile as administrator (its actually %PROGRAMFILES%\Git\etc\profile
or create a ~/.profile file containing the following:
GIT_PS1_SHOWDIRTYSTATE=1GIT_PS1_SHOWUPSTREAM='verbose git'export GIT_PS1_SHOWDIRTYSTATE GIT_PS1_SHOWUPSTREAM
with these environment variables set, the default msysGit prompt looks like this if you have a dirty tree with 1 commit ahead of origin:
pat@FROG /c/src/msysgit (devel * u+1)$ git status --short --branch## devel...origin/devel [ahead 1] M doc/git/html M etc/inputrc
step 1. Copy these two files to your home folder, you may find them under %PROGRAMFILES%\Git\etc\;
git-completion.bashgit-prompt.sh
step 2. Config your PS1 in your bash profile like .bashrc
, for example:
. git-completion.bash. git-prompt.shGIT_PS1_SHOWDIRTYSTATE=truePS1='\w\[\033[01;32m\]$(__git_ps1)\[\033[00m\]\$ '
The __git_ps1
function is defined in /git/config/completion/git-completion.bash
from within mingw bash. You should be able to copy this function to your own .bashrc and edit it as you choose.
FWIW I chose to skip __git_ps1 and to my own thing with color. Here's the prompt code from my .bashrc:
DEFAULT_COLOR='\[\e[0m\]'BLACK='\[\e[0;30m\]'LTBLUE='\[\e[1;34m\]'LTRED='\[\e[1;31m\]'USER_COLOR=$LTBLUEGIT_CHANGE_COLOR=$LTREDGIT_NO_CHANGE_COLOR="$BLACK"gitPrompt() { local gitPrompt=$(__git_ps1) local gitColor="$GIT_NO_CHANGE_COLOR" if [ -n "$gitPrompt" ]; then branch=$(git symbolic-ref HEAD 2>/dev/null) if [ "$gitPrompt" != " (${branch##refs/heads/})" ]; then gitColor="$GIT_CHANGE_COLOR" fi fi echo "$USER_COLOR\u@\h:\W$gitColor$gitPrompt$DEFAULT_COLOR$ "}PROMPT_COMMAND='PS1="$(gitPrompt)"'
The expression in PROMPT_COMMAND gets evaluated each time the prompt is printed.
To do what you want, you would probably have to parse the reflog with something like awk or perl and append that after the branch name. I usually rely on gitk to visualize the information you're looking for.