How do I ensure Git doesn't ask me for my GitHub username and password?
I am working with a repo on GitHub and everytime I try to push something, it asks for my GitHub username and password. I don't want it doing that.
I tried the instructions on setting your email in Git, namely set up the Git variables github.user and github.token, but that didn't make any difference.
I don't understand why this is happening.
Solution 1:
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.
Solution 2:
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.
Solution 3:
If you are using HTTPS instead of SSH , you can follow this :
-
Find your remote URL (remote.origin.url) with
git config -l
thanks to Sergio Morstabilini
Your remote URL will be like this : https://{USERNAME}@github.com/{USERNAME}/{REPONAME}.git
-
Execute this command :
git config remote.origin.url https://{USERNAME}:{PASSWORD}@github.com/{USERNAME}/{REPONAME}.git