Store credentials from a Git repository on Windows without SSH

6

How to configure Git in a local repository so that you do not ask for the login and password every time you make a push or pull?

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

    
asked by anonymous 26.11.2015 / 19:24

2 answers

4

There are two possibilities.

Accessing the repository via SSH

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

You must first change 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 should create a public key pair and private key, and configure them in Github (or the Git service you use). In this question I explain exactly how to do it.

Using the helper credential

Git still gives you the ability to store your username and password on a keychain , so that you can use HTTPS and do not need to report them all git pull and git push .

The only thing you need to do is tell Git to use the operating system keychain. 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 re-clone the repository via HTTPS (or do any operation that requires connection, such as git pull or git push ), enter user name and password, and Git will never ask you again.

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

    
26.11.2015 / 20:30
2

If it is msysgit in Windows 7 and do not worry about having your password open in a file use this method.

Open a command prompt and run:

setx HOME %USERPROFILE%

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

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

machine <hostname>
login <login>
password <password>
    
26.11.2015 / 20:57