bash 脚本从 bash 脚本添加 git 凭据

Sam*_*are 5 linux bash shell scripting

我需要能够将 git 凭据从我的 bash 脚本添加到我的 bash 脚本,但无法弄清楚如何做到这一点。

git clone https://xxxxxxx
Run Code Online (Sandbox Code Playgroud)

会询问我的用户名和密码。

我如何在 bash 脚本中传递这些?

任何指针将不胜感激

Ser*_*rgA 10

对于基本的 HTTP 身份验证,您可以:

  1. 在 url 内传递凭据:

    git clone http://USERNAME:PASSWORD@some_git_server.com/project.git
    
    Run Code Online (Sandbox Code Playgroud)

    警告这不安全:当您使用远程存储库时,您机器上的另一个用户可以使用pstop实用程序看到带有凭据的 url 。

  2. 使用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>
    
    Run Code Online (Sandbox Code Playgroud)
  3. 使用~/.netrc

    cat >>~/.netrc <<EOF
    machine some_git_server.com
           login <USERNAME>
           password <PASSWORD>
    EOF
    
    Run Code Online (Sandbox Code Playgroud)