Clone private repository by passing password as parameter

Asked

Viewed 3,334 times

4

I have a script on my production server that automates the entire process of checking new commits, generating the build and publishing the new changes.

It works perfectly with open repositories running code:

git clone -b meu-branch http://minha-url-repo.git

The problem is that in private repositories, when running the above command the terminal always returns a prompt asking for the repository access password. What causes the process to stop being automated (since someone would need to write the password).

Is there any way to pass the user and password next to the command git clone so that this command ran 100% automated?

Note: The user and password would be used readonly for security reasons, and the server is restricted.

1 answer

5

On an internal server, you can try using the following format:

git clone -b meu-branch http://usuario:[email protected]

However, keep in mind that this user URL and password will potentially appear in access logs, so unauthorized people, even from the company itself, may have access to the credential.

If it doesn’t work, you should check what types of protocol your Git server supports, as there are other alternatives.

Regardless of the outcome, a safer and more appropriate approach to this type of situation would be to use the SSH protocol with public key-based authentication. Also more secure, it avoids any type of fixed credential in your code.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.