Git push requires username and password

Question:

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 a username and password, but not when I’m using the laptop!

I don’t want to type my username and password every time I interact with origin. What am I missing here?

Answer:

A common cause is cloning using the default (HTTPS) instead of SSH. You can correct this by going to your repository, clicking “Clone or download”, then clicking the “Use SSH” button above the URL field and updating the URL of your origin remote like this:

You can check if you have added the remote as HTTPS or SSH using:

If you want to use HTTPS instead, run the following command to enable credential caching:

You should also specify caching expire,

After enabling credential caching, it will be cached for 7200 seconds (2 hour).