8

I Need to do a git pull using https url as a oneline command . this command I need to integrate in a bash script . But all the time it is asking the usernmae and password .

The repository is in AWS codecommit

Gavriel Cohen
  • 4,355
  • 34
  • 39
Tony Jose
  • 133
  • 1
  • 1
  • 9

3 Answers3

7

Try this:

git clone https://username:password@git-codecommit.us-east-1.amazonaws.com/v1../repos../..

This way worked for me for CodeCommit (AWS) repository

Gavriel Cohen
  • 4,355
  • 34
  • 39
  • 2
    Note that this won't work if the password contains characters illegal for the shell currently used, like "/" and "\" – f.cipriani May 27 '22 at 07:59
  • 2
    If your password contains characters illegal for the shell you can encode your password to URL (for example, @ will be %40 etc). You can see more here: https://stackoverflow.com/questions/22544219/how-do-i-use-special-characters-password-on-the-url-when-dealing-with-http-aut – Izabella Melo Jan 12 '23 at 21:05
4

Check this link: Enter user password in command

As is described perfectly in that post, you basically have three options:

  1. Store the password in .netrc file (with 600 permissions). Make sure you clone the repo specifying the username in the url.
  2. Clone the repo with https://user:pass@domain/repo . Take into account that your password will be visible in several places...
  3. Use the credential helper.
Jorge
  • 1,136
  • 9
  • 15
0

As an update, AWS has released their remote git remote codecommit. With proper IAM setup, you can do oneline pulls without even passing username and passwords. This is now the recommended method by AWS. It can be setup on your local or on a container that's running in an AWS Pipeline for example.

i.e. git clone codecommit://HelloWorldRepo myLocalHelloWorldRepo And then you can git pull as normal.

Full documentation is here: https://docs.aws.amazon.com/codecommit/latest/userguide/setting-up-git-remote-codecommit.html

Kent Wong
  • 566
  • 1
  • 6
  • 20