git clone and GIT_ASKPASS at a Git bash on Windows XP

1,462 views
Skip to first unread message

Peter Schaefer

unread,
Nov 21, 2010, 8:39:11 AM11/21/10
to msy...@googlegroups.com
I have several people to start a project by cloning a bunch of repositories. So I wanted to provide them a file containing the repository references and a Git bash script to read their personal passphrase, and execute git clone <repository> commands while looping through the repository references in the file. As the git clone command prompts for the passphrase I thought of feeding the initially read-in passphrase to the processes executing the git clone command. For some reason this does not work. git clone still prompts directly from the user. I have no clue why this does not work.

echo -n "Git key passphrase? "
read -s Passphrase
export Passphrase
for Repo in $(grep "^.*$" repositories); do
  GitCloneCmd="git clone "$Repo
  $GitCloneCmd << EOF
$Passphrase
EOF
done

Alternatively I tried using the GIT_ASKPASS environment variable. I let it point to a shell script passing the read-in passphrase to stdout. I wonder whether GIT_ASKPASS is supposed to work in Windows environment.

echo -n "Git key passphrase? "
read -s Passphrase
PassphraseEcho="echo -n $Passphrase;exit"
echo $PassphraseEcho >myGitAskPass.sh
export GIT_ASKPASS=myGitAskPass.sh
for Repo in $(grep "^.*$" repositories); do
  GitCloneCmd="git clone "$Repo
  $GitCloneCmd
done
rm myGitAskPass.sh

Pat Thoyts

unread,
Nov 23, 2010, 6:39:15 AM11/23/10
to Peter Schaefer, msy...@googlegroups.com

This is all a lot simpler is you use ssh keys and ssh agent. Or on
Windows, using putty for the ssh utility and pageant for the agent. An
ssh key agent will stay in memory. The user provides their passphrase
to unlock the key on startup and then the agent hands out the key on
request. In msysGit, if you set the environment variable GIT_SSH=plink
or %ProgramFiles%\TortoiseSVN\bin\TortoisePlink.exe if you have it
then this will fetch the pre-unlocked key from pageant when necessary.
The puttygen utility can create ssh keys or import ssh keys into a
format that pageant can use.

If you must -- there is 'git gui--askpass' which will throw up a
dialog to ask for the password then emits it to stdout. Text mode
password utilities tend to try to avoid stdin and ensure they really
are talking to the user. Usually 'expect' gets used to work around
these in the absence of something better like ssh keys.

Reply all
Reply to author
Forward
0 new messages