I have .sh
script that uses git for a pull request. While running it I always get requested for username and password. So how to make autofill for username?
pull.sh
contents:
cd /home/test/project
git pull
I have .sh
script that uses git for a pull request. While running it I always get requested for username and password. So how to make autofill for username?
pull.sh
contents:
cd /home/test/project
git pull
You could try using git-credential-cache. It will prompt for credentials just the first time.
To avoid username/password at alI I would suggest to use Ssh and Ssh keys for authentication (e.g: in gitlab).
Install expect
tool in your system
Do following Stuff in your bash file
*#!/usr/bin/expect -f*
cd /home/test/project
git pull
expect "sername"
send your_username
send "\r"
expect "assword"
send {your_password}
send "\r"
interact
Hope it works !
You can use expect script to interact with git to do git pull and then authentication.
#!/usr/bin/expect -f
spawn git pull
expect "username: " # write the keyword you get as prompt for entering username
send "your_username\r"
# remove the below 2 lines if you do not want script to interact for password.
expect "password: " # write the keyword you get as prompt for entering password
send "your_password\r"
interact
if you don't want to store password, you can enter it as an argument. For example:
#!/usr/bin/expect -f
set my_password [lindex $argv 0]
spawn git pull
expect "username: " # write the keyword you get as prompt for entering username
send "your_username\r"
expect "password: " # write the keyword you get as prompt for entering password
send "${my_password}\r"
interact
Run this script as ./myScript.sh <password>
.