Clone private repository passing password as parameter

4

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

It works perfectly with open repositories, by running the code:

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

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

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

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

asked by anonymous 17.02.2016 / 03:45

1 answer

4

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 URL with the username and password will potentially appear in access logs, so unauthorized people, even from the company itself, can access the credential.

If it does not work, you should check what protocol types your Git server supports, as there are other alternatives.

Regardless of the result, a more secure and more appropriate approach to this type of situation would be to use the SSH protocol with public key based authentication. In addition to being safer, it avoids any kind of fixed credentials in your code.

    
17.02.2016 / 04:35