2

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.

John Kugelman
  • 349,597
  • 67
  • 533
  • 578
subhra_user
  • 439
  • 5
  • 19
  • 1
    https://stackoverflow.com/questions/10054318/how-do-i-provide-a-username-and-password-when-running-git-clone-gitremote-git – itachi Mar 15 '21 at 03:27
  • @itachi, I have also checked this link. How I will add the `username and password` with URL dynamically. As I am new to bash script that is my concern only. – subhra_user Mar 15 '21 at 03:42

1 Answers1

4

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"
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250