我需要能够将我的 git 凭据添加到我的 bash 脚本中,但不知道该怎么做。
git clone https://xxxxxxx
会询问我的用户名和密码。
我如何在 bash 脚本中传递这些?
不胜感激
最佳答案
对于基本的 HTTP 身份验证,您可以:
在 url 中传递凭据:
git clone http://USERNAME:PASSWORD@some_git_server.com/project.git
WARN 这是不安全的:当您工作时,您机器上的其他用户可以使用
ps
或top
实用程序看到带有凭据的 url带远程仓库。使用 gitcredentials :
$ git config --global credential.helper store $ git clone http://some_git_server.com/project.git Username for 'http://some_git_server.com': <USERNAME> Password for 'https://USERNAME@some_git_server.com': <PASSWORD>
使用
~/.netrc
:cat >>~/.netrc <<EOF machine some_git_server.com login <USERNAME> password <PASSWORD> EOF
关于linux - bash 脚本从 bash 脚本添加 git 凭据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53914241/