1

I have written a simple NodeJS HTTPS listener to receive a POST with an authentication token, and git credentials. This will be run when a Web Hook hits the end-point URL after code is returned to the repository.

What I'd like to do is take those credentials and run a git pull on a repository that is on that host utilizing those credentials (and then kick off some other stuff, which is out of the scope of this question).

Ideally, I'd love to:

  1. Run a command to store the username and password into the git credential manager
  2. Run a git pull which will utilize those credentials.
  3. Erase the credentials from the git credential manager

I will be doing all of this via NodeJS, but I think that should mostly be irrelevant for my question. If I know a command-line way to set / clear credentials I should be in good shape.

Can anyone point me in the right direction? I've been having a really hard time deciphering the git help documentation on this. Everything mentions typing in the credentials from a person, and then having them still there later for the script to use. Our security group will not let us do that.

As a result we need the credentials entered, and later cleared, from a script.

Doug
  • 6,446
  • 9
  • 74
  • 107

1 Answers1

1

This isn't exactly what I asked for, but it works in my use case. Apparently, the git pull command supports specifying a repository rather than defaulting to the one in the repo. As a result I can do the following for my specific use case:

git pull https://[URL_ENCODED_USERNAME]:[URL_ENCODED_PASSWORD]@[NORMAL_ENDPOINT_URL]

I was told by a friend that this could cause the URL with PWD to show with the following command and it might need to be removed for security:

git remote -v

However, at least with my version of git (2.17.1), I did not find the credential filled URL to show up anywhere. As a result, I can cover all three steps simply by doing a git pull with the URL in it.

The nice thing about this is that it now makes it so I can utilize pretty much any of the lightweight git wrapper's for NodeJS, or I might just do a spawn its so simple.

Doug
  • 6,446
  • 9
  • 74
  • 107
  • If you had originally cloned the repo using the URL with credentials, then it would probably show up in your 'git remote -v' output. With 'git pull ' it must just be transient. – John Michelau May 07 '20 at 19:17