Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

bash script adding git credentials from bash script

I need to be able to add git credentials from my to my bash script but can't figure out how to do this.

git clone https://xxxxxxx

would ask for my username name and password.

how to i pass these in a bash script ?

any pointers would be appreciated

like image 262
Samuel Dare Avatar asked Dec 24 '18 13:12

Samuel Dare


People also ask

How do I add generic credentials to Git?

Or finding it via the Control Panel -> Manage Windows Credentials. Go to Windows Credentials -> Generic Credentials. Here your credential should be listed if everything is working correctly. Git should add it by default the first time you log in to a new repository.


1 Answers

For basic HTTP authentication you can:

  1. Pass credentials inside url:

    git clone http://USERNAME:PASSWORD@some_git_server.com/project.git
    

    WARN this is not secure: url with credentials can be seen by another user on your machine with ps or top utilities when you work with remote repo.

  2. Use 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>
    
  3. Use ~/.netrc:

    cat >>~/.netrc <<EOF
    machine some_git_server.com
           login <USERNAME>
           password <PASSWORD>
    EOF
    
like image 93
SergA Avatar answered Oct 14 '22 19:10

SergA