Store credentials from a Git repository on Windows without SSH

Asked

Viewed 3,602 times

6

How to set up Git in a local repository so you don’t ask for the login and password every time you push or pull?

My Git server does not support SSH. HTTP only. I have only the username and the password user in Git.

  • http://oraculum.blog.br/blogoraculum/index.php/salvar-senha-do-git-no-windows-com-git-credential-winstore/ take a look at this link

  • Which S.O.? Windows or Linux?

  • Windows @Marcosregis

2 answers

5


There are two possibilities.

Accessing the repository via SSH

Configure me project to access the repository using a public key and private key pair.

First you must change the origin to access the remote repository via the SSH protocol instead of the HTTPS protocol (this path you see on the repository page):

git remote set-url origin git://<caminho do seu repositório>

Then you must create a public key and private key pair, and configure them on Github (or the Git service you use). In that question I’ll explain how to do it.

Using the helper credential

Git still gives the possibility of store your user and password in a Keychain own, if so that you can use HTTPS and do not need to inform them at all git pull and git push.

The only thing you need to do is tell Git to use the Keychain of the operating system. Below are the procedures for each of them.

Linux:

git config --global credential.helper cache

OSX:

git config --global credential.helper osxkeychain

Windows:

git config --global credential.helper wincred

After that just clone the repository via HTTPS (or do any operation that requires connection, such as git pull or git push), enter username and password, and Git will never ask them again.

PS: the helper credential is only available in version 1.7.10 up; check the version of Git installed with git -v.

  • I forgot to ask my Git server does not support SSH. I only have the "username" and "password" to use the Git server.

  • I get it. I changed the answer to your needs.

  • I typed the command Credential helper, but gave no further option to enter the credentials.

  • The only thing you need to do is tell Git to use the Keychain of the operating system. In the case of Linux this command is git config --global credential.helper cache; in the OSX is git config --global credential.helper osxkeychain; and in Windows is git config --global credential.helper wincred. After that just clone the repository via HTTPS, enter user and password, and Git will never ask them again.

  • Cool. It worked! I think it is interesting to put these commands in your answer, because the solution will be immediately available to others who arrive here. Vlw!

  • Cool, thanks! I complemented the answer as your suggestion. :)

Show 1 more comment

2

If you are msysgit on Windows 7 and don’t worry about having your password open in a file use this method.

Open a command prompt and run:

setx HOME %USERPROFILE%

The variable %HOME% will be created with the value 'C:\Users\SEU USUARIO'

Now open this directory and create a file with the name _netrc with the following content

machine <hostname>
login <login>
password <password>
  • I did what you wrote but it wasn’t.

  • how was your _netrc file?

  • It looks like this: machine https://gitlab... login myUsername password myNew

Browser other questions tagged

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