0

I'm trying to git clone a remote repository by using a simple bash script, but I could not get pass the prompt where github asks for my username and password. Here is my condensed version of the script:

#!/bin/bash
REPO=$1
USERNAME=$2
PASSWORD=$3
git clone $REPO
expect "Username for 'https://github.com':"
send $USERNAME

The send command does not seem like it is passing the USERNAME variable because the prompt never get pass the "Username for 'https://github.com':"

I tried piping and heredoc methods without any luck. Any help is gladly appreciated.

Thanks!

norrin
  • 171
  • 8
  • 1
    You could avoid using `expect` and form the command to be executed with the username and password... As seen here: https://stackoverflow.com/questions/10054318/how-to-provide-username-and-password-when-run-git-clone-gitremote-git –  Sep 15 '17 at 17:30
  • Thanks a bunch! will try this out. – norrin Sep 15 '17 at 17:39
  • It works with one caveat, urlencode any special characters in the password. – norrin Sep 15 '17 at 18:19
  • why not save your ssh key in github and clone repos without having to pass credentials? – guessimtoolate Sep 15 '17 at 22:25
  • I may not be the only one to use this script. – norrin Sep 16 '17 at 05:19

1 Answers1

0

You can include credentials in the git push command like so:
git push https://<USER>:<PASS>@github.com/asdf/blah.git
I hope this helps; let me know if this doesn't work.
jBit

jBit
  • 41
  • 1
  • 9