I cloned a git repository from my Github account to my PC.
I want to work with both my PC and laptop, but with one Github account.
When I try to push to or pull from Github using my PC, it requires username and password, but not when using the laptop!
I don't want to type my username and password every time I interact with origin. What I am missing here?
As many users has said, you just have to change your git repositorie URL from https to SSH.
If you haven't generated a SSH key in your machine, then your are going to have to do it.
Just as an additional information, after doing this change I still was getting the same error: Permission Denied.
In my case, the problem was that I was using the Windows Shell to execute the ngh command; since this command should open a prompt to request the SSH phrase and the Windows Shell doesn't open this kinds of prompts, the authentication just failed.
So, I just had to open the git shell and execute the ngh command there, put the SSH phrase in the prompt every time it asked for it and "voilà"... It just worked fine!
You can cache your GitHub password in Git:
Just follow the instructions from the github's official documentation.
After following the instructions from the above link, you should be able to push/pull to/from your repo without typing your username/password every time.
If the ssh key or .netrc did not work for you then another simple but less secure solution that could work for you is git-credential-store - Helper to store credentials on disk
By default credentials will be saved in
~/.git-credentials
. It will be created and written to.Please note using this helper will store your passwords unencrypted on disk, protected only by filesystem permissions. If this may not be an acceptable security tradeoff.
Update for HTTPS:
Github has launched a new program for Windows that stores your credentials when you're using HTTPS:
To use:
Download the program from here
Once you run the program it will edit your
.gitconfig
file. Recheck if it edited the correct.gitconfig
in case you have several of them. If it didn't edit the correct one, add the following to your.gitconfig
NOTE the line break after
[credential]
. It is required.Open up your command line client and try
git push origin master
once. If it asks you for a password, enter it and you're through. Password saved!Apart from changing to SSH you can also keep using HTTPS, if you don't mind to put your password in clear text. Put this in your
~/.netrc
and it won't ask for your username/password (at least on Linux and Mac):Addition (see VonC's 2nd comment): on Windows the file name is
%HOME%\_netrc
.Also read VonC's first comment in case you want to encrypt.
Another addition (see user137717's comment) which you can use if you have git 1.7.10 or newer.
Cache your github password in git using a credential helper :
This also works on Linux, Mac and Windows.
I had the same same issue.
so change the .git/config file from my project
to
and add the ssh public key to the git profile which is in setting.
for ssh public key