1

The command prompt in Git Bash displays the current branch name (with other information such as directory name, etc) as given below.

mylogin@SYSNAME MINGW64 ~/path/to/my/repo (master)
$

How can I include the repo user profile email along with the branch name? The email is the user.email of the repo; which can be found using the command git config user.email.

I would like to have this value git config user.email in my command prompt along with the branch name as given below.

mylogin@SYSNAME MINGW64 ~/path/to/my/repo (master|myemail@github.com)
$

Please note I have a windows system.

Vijey
  • 6,536
  • 7
  • 43
  • 50
  • 1
    Apply the result of `git config user.email` to your `PS1` environment variable to obtain the email and `git rev-parse --abbrev-ref HEAD 2> /dev/null | tr -d '\n'` to obtain the current branch. – Lyubomyr Shaydariv Jan 11 '17 at 08:51
  • This one might be interesting to you: http://stackoverflow.com/questions/4133904/ps1-line-with-git-current-branch-and-colors – Lyubomyr Shaydariv Jan 11 '17 at 08:56

1 Answers1

1

Well... The MinGW approach slightly differs from a "usual" bash approach because it has a very rich script to generate the PS1 Bash variable. You just have to to the following (assuming you're using 64-bit too):

  • find /mingw64/share/git/completion/git-prompt.sh or (%YOUR_GIT_LOCATION%\mingw64\share\git\completion\git-prompt.sh);
  • modify the gitstring environment variable:
    replace local gitstring="$c$b${f:+$z$f}$r$p"
    with local gitstring="$c$b${f:+$z$f}$r$p|$(git config user.email)".

The diff between my original version and my version with the user.email setting:

diff --git a/git-prompt.sh.BAK b/git-prompt.sh
index 07b52be..2d63680 100644
--- a/git-prompt.sh.BAK
+++ b/git-prompt.sh
@@ -515,7 +515,7 @@ __git_ps1 ()
        fi

        local f="$w$i$s$u"
-       local gitstring="$c$b${f:+$z$f}$r$p"
+       local gitstring="$c$b${f:+$z$f}$r$p|$(git config user.email)"

        if [ $pcmode = yes ]; then
                if [ "${__git_printf_supports_v-}" != yes ]; then
Lyubomyr Shaydariv
  • 20,327
  • 12
  • 64
  • 105
  • Thanks Lyubomyr. It worked. I could see both branch and email in my git bash command prompt. – Vijey Jan 12 '17 at 15:01