subhra_user
subhra_user

Reputation: 439

How to clone git repo using shell script with username and password

I need to clone git branch into my local directory using a shell script.

#!/bin/sh

echo $0
 
full_path=$(realpath $0)

dir_path=$(dirname $full_path)
 
root_dir=$(dirname $dir_path )

REPO_DIR="${root_dir}/utils"

username="test1"
password="testpass"

BRANCH_NAME="test-cd"

GIT_URL="https://wwwin-example.com/internal/demo.git"


GIT=`which git`

cd ${REPO_DIR}

${GIT} clone -b ${BRANCH_NAME} ${GIT_URL}

Here I am doing clone one branch my directory but here I need to use username and password along with the git command so that user will not provide it later. Once this script will run then the git clone command with username and password will fetch the branch to my local directory.

Upvotes: 2

Views: 4732

Answers (1)

VonC
VonC

Reputation: 1324337

How I will add the username and password with URL dynamically

You can use your variables in GIT_URL:

GIT_URL="https://${username}:${password}@wwwin-example.com/internal/demo.git"

Upvotes: 5

Related Questions