Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git push requires username and password

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?

like image 259
TooCooL Avatar asked Jul 03 '11 20:07

TooCooL


People also ask

How do I stop git push from asking for username and password?

Issue the command git fetch/push/pull. You will not then be prompted for the password.

Why is git asking for username and password every time?

If Git prompts you for a username and password every time you try to interact with GitHub, you're probably using the HTTPS clone URL for your repository. Using an HTTPS remote URL has some advantages compared with using SSH.

How do I pass a git push command password?

As explained in the manual, to store the password, you should use an external credential helper. For Windows, you can use the Windows Credential Store for Git. This helper is also included by default in GitHub for Windows. When using it, your password will automatically be remembered, so you only need to enter it once.


2 Answers

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:

git remote set-url origin [email protected]:username/repo.git 

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

git remote -v 

This is documented at GitHub: Switching remote URLs from HTTPS to SSH.

like image 186
Tekkub Avatar answered Sep 22 '22 07:09

Tekkub


Permanently authenticating with Git repositories

Run the following command to enable credential caching:

$ git config credential.helper store $ git push https://github.com/owner/repo.git  Username for 'https://github.com': <USERNAME> Password for 'https://[email protected]': <PASSWORD> 

You should also specify caching expire,

git config --global credential.helper 'cache --timeout 7200' 

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

like image 32
Jaykumar Patel Avatar answered Sep 22 '22 07:09

Jaykumar Patel