I have written scripts for Windows and Linux to essentially set up a new users workspace with all the git repositories from our server.
I would like the user to enter the password for our server once, store it in a local variable, pass that variable to each git pull
command, then erase the password variable and exit.
How can I input the password when the git pull
command requests it? Both for Windows batch file and a Linux shell script.
Here is code from the Linux script:
#!/bin/bash echo "Enter password: " read pswd clear #No screen peaking #This is repeated for each repo location=folderName mkdir $location cd $location git init git remote add origin git@<server>:$location.git git pull origin master #Above prompts for password & is where I want to automatically input $pswd
I've tried various things recommended on SO and elsewhere, such as piping, reading from .txt file, etc. I would prefer to not need anything more than plain old windows cmd and Linux terminal commands. And as this script is just for set up purposes, I do not need to securely store the password permanently with something like ssh agent.
I'm running Windows 7 and Ubuntu 12.10, but this script is meant for setting up new users, so it should ideally work on most distributions.
The most likely reason for this is that Git has been configured to use a credential helper. The configuration could have been made a) for all users in your system b) only for your user c) for a specific repository.
Synopsis:
git pull "https://<username>:<password>@github.com/<github_account>/<repository_name>.git" <branch_name>
Example:
git pull "https://admin:[email protected]/Jet/myProject.git" master
Note: This works for me on a bash script
I would really recommend to not try and manage that password step, and delegate that (both on Linux and Windows) to git credential helper.
See:
The user will enter the password only once per session.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With