You can still pass in the username and password into the URL for git clone
:
git clone https://username:password@github.com/username/repository.git
As for using a bash script, You can pass the username $1
and password $2
:
git clone https://$1:$2@github.com/username/repository.git
Then call the script with:
./script.sh username password
Addtionally, It might be more secure to leave the password out and only include the username:
git clone https://$1@github.com/username/repository.git
Since the command with your password will be logged in your bash history. However, you can avoid this by adding a space in front of the command.
You can also use How do I parse command line arguments in Bash? for nicer ways to use command line arguments.
Also be careful to use URL Encoding for special characters in usernames and passwords. A good example of this is using %20
instead of @
, since URLS need to use standard ASCII encoding for characters outside the standard character set.