0

I am making a batch file that automatically clone our repository, but it will ask for a password input before it can proceed. What i want is that i'll just hard code (or if there is another way) my password. and if it prompts/ask a password, it will automatically input the password i specified in my code... base on my little research (coz most of them are just the same solution)...

i got a code like this

@echo off

echo <password>| git clone <repository url> <output path>

pause

but it doesnt seem to do the trick.

can anyone help me? please???

John
  • 1
  • 1
  • 5
  • 2
    Possible duplicate of [How to provide username and password when run "git clone git@remote.git"?](https://stackoverflow.com/questions/10054318/how-to-provide-username-and-password-when-run-git-clone-gitremote-git) –  Jun 30 '17 at 09:44

1 Answers1

1

You can simply use the user:password in the clone URL (http://user:password@myserver.com/repo.git)

Or you can use GIT_ASKPASS, so in your batch file:

  • create another batch file that do the echo
  • set the environment variable GIT_ASKPASS to the path to the echo batch file
  • call git
  • remove the echo batch file

In a windows batch file it could be something like that (inspired from jenkins-git-client):

@echo off

REM Create askpass batch
>askpass.bat  echo @set arg=%%~1
>>askpass.bat echo @if (%%arg:~0,8%%)==(Username) echo USERNAME
>>askpass.bat echo @if (%%arg:~0,8%%)==(Password) echo PASSWORD
set GIT_ASKPASS=%cd%\askpass.bat

REM Clone
git clone <repository url> <output path>

REM Remove askpass batch
del askpass.bat

Not sure if git will accept a batch file as ASKPASS or if you have to use a shell script, but I hope you get the idea.

zigarn
  • 10,892
  • 2
  • 31
  • 45
  • Updated again, should work better. I'm not good in windows batch files. – zigarn Jul 04 '17 at 06:39
  • still doesnt work for me < -- (@)set arg= (@)if (~0,8 ) echo hots --> is this supposed to be the output.. – John Jul 05 '17 at 05:36
  • Still Not Working :( – John Jul 06 '17 at 01:18
  • Try to add debug output (`>>askpass.bat echo @echo %%arg%% ^>^&2`) after the first `>askpass.bat` line. Then provide the output you get. – zigarn Jul 06 '17 at 08:10
  • ill answer this later.. there is an issue here.. not related to this problem though.. but related to the repository – John Jul 07 '17 at 01:36