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.
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"
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.