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???

1

1 Answer 1

2

You can simply use the user:password in the clone URL (http://user:[email protected]/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.

Sign up to request clarification or add additional context in comments.

5 Comments

Updated again, should work better. I'm not good in windows batch files.
still doesnt work for me < -- (@)set arg= (@)if (~0,8 ) echo hots --> is this supposed to be the output..
Still Not Working :(
Try to add debug output (>>askpass.bat echo @echo %%arg%% ^>^&2) after the first >askpass.bat line. Then provide the output you get.
ill answer this later.. there is an issue here.. not related to this problem though.. but related to the repository

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.