下面是一个示例的bash脚本,用于添加git凭据:
#!/bin/bash
# 输入git用户名和密码
read -p "Enter your git username: " username
read -sp "Enter your git password: " password
echo
# 添加git凭据
git config --global credential.helper store
printf "https://$username:$password@github.com" | git credential-store store
echo "Git credentials added successfully."
这个脚本使用了read
命令来读取用户输入的git用户名和密码,并使用git config
命令配置全局的credential helper为store
,然后使用printf
命令将git凭据添加到credential store中。
请注意,这种方式存储的git凭据将以明文形式保存在磁盘上,因此请确保将脚本设为私密,仅在受信任的环境中使用。
另外,建议使用密钥认证或者其他安全的认证方式来代替明文的凭据。