Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Supplying a password to Git in a Bash script

Tags:

git

bash

From a Bash script I would like to supply a password. I have tried the following:

echo 'mypass' | git pull

git pull < 'mypass'

git pull < echo 'mypass'

None seem to work.

like image 617
jax Avatar asked Jul 04 '15 08:07

jax


People also ask

How do I pass a user ID and password in Git clone?

username and password. We can supply the username and password along with the git clone command in the remote repository url itself. The syntax of the git clone command with the http protocol is, git clone http[s]://host. xz[:port]/path/to/repo.

How do I authenticate Git in terminal?

There are three main approaches you can take: Using a personal authentication token or password. Using an SSH key. Using your GitHub password with 2-factor authentication.


1 Answers

  1. Create file git_password.sh with content:

    #!/bin/sh
    exec echo "$GIT_PASSWORD"
    
  2. Assign your password to the GIT_PASSWORD environment variable

    $ GIT_PASSWORD=your_password
    
  3. Execute git command with GIT_ASKPASS environment variable. It will force password prompt and execute git_password.sh as callback:

    $ GIT_ASKPASS=./git_password.sh git clone $REPO
    
like image 188
Sergey Bezugliy Avatar answered Oct 21 '22 21:10

Sergey Bezugliy