[英]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.