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.

2
  • 1
    stackoverflow.com/questions/10054318/… Commented Mar 15, 2021 at 3: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. Commented Mar 15, 2021 at 3:42

1 Answer 1

5

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"
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.