48

I'm using git on a new git linux computer. When I do git push, it me asks for user/password.

I've setup git properly, and in fact cloning the repo from github into a new folder works perfectly (using my public key, not the readonly copy). When I try to push from a previous clone I made to the same repo I get prompted for a user/pass.

Of course sshing into [email protected] works, and I made sure my public key is configured in github. Any ideas how to continue debugging?

7 Answers 7

81

this occurs because you did

git clone https://github.com/username/repo

instead of

git clone [email protected]:username/repo.git
Sign up to request clarification or add additional context in comments.

1 Comment

sometimes thats not an option!
57

Try the following:

git remote set-url origin [your git url, such as [email protected]:.../project.git]

4 Comments

After I run this I get "Enter passphrase for key '/u/.ssh/id_rsa':" which I know the password, but is there a way for it to stop asking this based on a key file being in place?
To avoid entering your password for your key with each push, try ssh-add. You'll need ssh-agent running to add the keys to your SSH agent. A simple man page here
Whew you're the one persron who actually gave the solution instead of just saying what the problem is!
I did this and it still asks for username. Might only work with certain URLs.
44

What do you mean by previous repo? Check the url of the origin from the previous repo's .git/config file. If you had cloned using http, it will ask for user/pass.

1 Comment

You're right, the problem was an HTTP URL. By "a previous repo" I meant a previous clone of the same repo.
7

if your repo Url is: https://github.com/abc/xyz.git

set url from command line as: git remote set-url origin [email protected]:abc/xyz.git

Replace https://github.com/ with [email protected]:

1 Comment

but not if the repo doesnt support ssh proto
2

In my experience, there are three cases

1. git remote set-url github(remote repo name) https://github.com/id/a.git
    it asks ID/Passwd
2. git remote set-url github https://[email protected]/id/a.git
    it only asks Passwd
3. git remote set-url github git://github.com:id/a.git
    if you don't have a permission, it complains. So I can't use this for public server of github

all the commands are written to ".git/config"

1 Comment

Fixed my HTTPS was missing the username before @github.com
1

for mac If you have git 1.7.10+ it needs to use credential-osxkeychain for password caching. Here is a nice explanation:

https://help.github.com/articles/set-up-git

Comments

1

May be this will help someone like me.

Please find Git official article for caching your password

enter image description here

Link: https://help.github.com/en/articles/caching-your-github-password-in-git

Commands:

  1. Set Git to use the credential memory cache

    > git config --global credential.helper cache

  2. Change default cache timeout

    > git config --global credential.helper 'cache --timeout=3600'

1 Comment

This caches the username and password, but will still have to enter both when cache expires.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.