How do I ensure Git doesn't ask me for my GitHub username and password?

Had a similar problem today: I messed things up in my working copy, so I decided to rename the directory and clone my project again from github. But after doing that, I had to enter my password to do any pull/push request, instead of entering the passphrase just once as I used to.

That was because today I used the https protocol to clone the project! To check what protocol you're using just run

git config -l

and look at the line starting with 'remote.origin.url'.

To switch protocols:

git config remote.origin.url [email protected]:the_repository_username/your_project.git

the_repository_username and your_project should be replaced with the appropriate repository name and the owner of that repository. The username will be yours if you own the repository, or the repository owner's username otherwise.


You need to set-up an ssh-agent against which you only need to authenticate once. See this answer over at SO for a howto.


If you are using HTTPS instead of SSH , you can follow this :

  1. Find your remote URL (remote.origin.url) with

    git config -l
    

    thanks to Sergio Morstabilini

  2. Your remote URL will be like this : https://{USERNAME}@github.com/{USERNAME}/{REPONAME}.git

  3. Execute this command :

    git config remote.origin.url https://{USERNAME}:{PASSWORD}@github.com/{USERNAME}/{REPONAME}.git
    

Tags:

Git

Login

Github