Cygwin/Git Bizarre Terminal Issue

Solution 1:

OK, I think I've found a definite solution.

The problem is that, regardless of the terminal used (puttycyg, mintty, cmd.exe), Git by default, in the absence of better configured alternatives, tries to use a "simple password prompt" (as you can read in the description of core.askpass config option).

The simple password prompt apparently only works on real UNIX, but not on Cygwin.

The solution is to install an SSH_ASKPASS compatible program for Windows and configure Git to use it.

What I did was:

  1. Install win-ssh-askpass application by unpacking and copying to C:\
  2. Download and install the Borland Delphi 5 runtime required by win-ssh-askpass (hard to come by nowadays, but found one on http://www.satsignal.eu/software/runtime.html)
  3. Configure Git to obtain passwords using win-ssh-askpass: git config --global core.askpass "C:/win_ssh_askpass.exe". Note that the EXE file has underscores in its name, not minus signs.
  4. Remember to always place your login in the URL (https://<user>@<domain>/<repository>). Otherwise, Git will ask for the login before asking for the password, using the same askpass utility. You may unknowingly input your password as the login, which will be sent to the webserwer and logged in its access log as plain text!

Now Git asks for the password using an elegant GUI window and works regardless of the terminal used :)

Solution 2:

I've experienced the same issue - however in my case I am SSH'd in the Cygwin server so obviously a Win32 GUI askpass won't work.

Instead, I wrote this simple script to do the askpass. I though it could be used from regular prompts as well by getting the tty device from /bin/tty.exe but that didn't work for an unknown reason (feel free to tty yourself or look for another solution to get the tty, maybe I just got it wrong somehow).

/bin/askpass.sh:

#!/bin/bash

TTY=$SSH_TTY
[ -c "$TTY" -a -r "$TTY" -a -w "$TTY" ] \
  || { echo "Failed to open device \`$TTY'!"; exit 1; }
exec <$TTY

echo -n "$@" >$TTY
read -s P
echo >$TTY

echo $P

Make sure this script is executable and use it as your git's core.askpass setting. Since this script relies on the $SSH_TTY variable it will normally only work from SSH. You could however set $SSH_TTY in .bashrc or .bash_profile if unset; this way it should work even from a console. The following line in your rc script should do it:

[ -z "$SSH_TTY" ] && export SSH_TTY=$(/bin/tty.exe)