[英]How to clone git repo using shell script with username and password
我需要使用 shell 脚本将 git 分支克隆到我的本地目录中。
#!/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}
在这里,我正在克隆我的目录的一个分支,但在这里我需要使用username and password
以及 git 命令,以便用户以后不会提供它。 一旦此脚本运行,则带有用户名和密码的git clone
命令会将分支获取到我的本地目录。
我将如何使用 URL 动态添加用户名和密码
您可以在GIT_URL
中使用您的变量:
GIT_URL="https://${username}:${password}@wwwin-example.com/internal/demo.git"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.