387

I'm the owner of an organization on github and just created a repo and tried pushing but I'm running into an issue where it's asking me for my username even though I can SSH just fine:

$ ssh -T [email protected]
Hi Celc! You've successfully authenticated, but GitHub does not provide shell access.
$ git add .
$ git commit -m 'first commit'
[master (root-commit) 3f1b963] first commit
 6 files changed, 59 insertions(+)
 create mode 100644 .gitignore
 create mode 100644 main.js
 create mode 100644 package.json
 create mode 100644 readme.markdown
 create mode 100644 views/index.ejs
 create mode 100644 views/layout.ejs
$ git remote add origin https://github.com/WEMP/project-slideshow.git
$ git push -u origin master
Username for 'https://github.com':

What am I doing wrong? This has never happened to me before but I recently also upgraded to git 1.7.10.3.

12 Answers 12

819

Don't use HTTP use SSH instead

change

https://github.com/WEMP/project-slideshow.git 

to

[email protected]:WEMP/project-slideshow.git

you can do it in .git/config file

7
63

I had this same issue and wondered why it didn't happen with a bitbucket repo that was cloned with https. Looking into it a bit I found that the config for the BB repo had a URL that included my username. So I manually edited the config for my GH repo like so and voila, no more username prompt. I'm on Windows.

Edit your_repo_dir/.git/config (remember: .git folder is hidden)

Change:

https://github.com/WEMP/project-slideshow.git

to:

https://*username*@github.com/WEMP/project-slideshow.git

Save the file. Do a git pull to test it.

The proper way to do this is probably by using git bash commands to edit the setting, but editing the file directly didn't seem to be a problem.

1
  • That's a good point, if you include the username it'll be handled by the OS keychain (at least it should in OSX, and apparently in Windows too). There's no difference between editing the file with notepad or with vim/emacs/nano/vi, I wouldn't worry so much about technical snobbery it's just a plain text file anyways.
    – Kit Sunde
    Commented Feb 28, 2013 at 20:19
35

Here is an official answer to this:

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: it's easier to set up than SSH, and usually works through strict firewalls and proxies. However, it also prompts you to enter your GitHub credentials every time you pull or push a repository.

You can configure Git to store your password for you. If you'd like to set that up, read all about setting up password caching.

2
  • 1
    Thanks. I would argue with Github that it's not easier to setup if you end up here (:
    – ecoologic
    Commented Mar 30, 2019 at 23:34
  • This is an answer for a question because the question ask, WHY?
    – eli
    Commented Jul 31, 2019 at 5:08
20

Improving upon @Ianl's answer,

It seems that if 2-step authentication is enabled, you have to use token instead of password. You could generate a token here.

If you want to disable the prompts for both the username and password then you can set the URL as follows -

git remote set-url origin https://username:[email protected]/WEMP/project-slideshow.git

Note that the URL has both the username and password. Also the .git/config file should show your current settings.


Update 20200128:

If you don't want to store the password in the config file, then you can generate your personal token and replace the password with the token. Here are some details.

It would look like this -

git remote set-url origin https://username:[email protected]/WEMP/project-slideshow.git
2
  • 1
    Is this secure? Can someone just access this information from my computer?
    – Akaisteph7
    Commented Sep 24, 2019 at 14:41
  • Yes, they can access from your computer since they are stored in plain text in .git/config file
    – kaushal
    Commented Jan 17, 2020 at 16:32
16

an additional note:

if you have already added a remote ($git remote add origin ... ) and need to change that particular remote then do a remote remove first ($ git remote rm origin), before re-adding the new and improved repo URL (where "origin" was the name for the remote repo).

so to use the original example :

$ git remote add origin https://github.com/WEMP/project-slideshow.git
$ git remote rm origin
$ git remote add origin https://[email protected]/WEMP/project-slideshow.git
1
  • 8
    You don't have to remove the remote. You can just change the URL: git remote set-url origin https://[email protected]/WEMP/project-slideshow.git
    – shovavnik
    Commented Dec 23, 2013 at 10:59
11

If you're using HTTPS, check to make sure that your URL is correct. For example:

$ git clone https://github.com/wellle/targets.git
Cloning into 'targets'...
Username for 'https://github.com': ^C

$ git clone https://github.com/wellle/targets.vim.git
Cloning into 'targets.vim'...
remote: Counting objects: 2182, done.
remote: Total 2182 (delta 0), reused 0 (delta 0), pack-reused 2182
Receiving objects: 100% (2182/2182), 595.77 KiB | 0 bytes/s, done.
Resolving deltas: 100% (1044/1044), done.
1
  • 3
    That's a great point! If you have a typo in the URL, you will be prompted for the 'Username' instead of being told that the repository does not exist.
    – dmitrii
    Commented Oct 27, 2017 at 4:24
6

I've just had an email from a github.com admin stating the following: "We normally advise people to use the HTTPS URL unless they have a specific reason to be using the SSH protocol. HTTPS is secure and easier to set up, so we default to that when a new repository is created."

The password prompt does indeed accept the normal github.com login details. A tutorial on how to set up password caching can be found here. I followed the steps in the tutorial, and it worked for me.

1
5

Because you are using HTTPS way.HTTPS requires that you type your account access every time you try to push or pull,but there is one way too, called SSH, and it lets you to tell git, that I give you permission with my account for this pc, and never ask me again about any user access. To use it, you have to generate SSH key and add it into your Github's account just one time.To do that, you can follow these steps

How To Generate SSH key for Github

5

If you've enabled two factor authentication, then you'll need to generate a personal access token and use that instead of your regular password. More info here: https://help.github.com/articles/creating-an-access-token-for-command-line-use/

1
  • Neil I believe this is a useful info, but I doubt it may not qualify as an answer. Commented Jun 30, 2017 at 7:18
2

As pointed out by other users, the problem is that if you type

git config --list

you will see that

remote.origin.url= ...

starts with https.

This makes github trying to authenticate you via user and password, while the recent system requires you to authenticate via ssh key.

Assuming you have already exchanged ssh keys between github and your pc, you can fix the issue by changing the value of remote.origin.url to the one supporting ssh key authentication.

Method 1

git remote set-url --delete origin 'https://github.com/<your_github_user>/<your_github_repo>'

git remote set-url --add origin [email protected]:/<your_github_user>/<your_github_repo>.git

Check that the change is correct by running again

git config --list

Method 2

Otherwise you can run

git config --list --show-origin

and look up the line containing remote.origin.url and manually edit the file pointed by file: in order to change the value of remote.origin.url

e.g.

vim  .git/config

This second method is useful in case something went wrong with the first one and git couldn't correctly delete the first line of remote.origin.url, returning a message like

fatal: '=' does not appear to be a git repository

fatal: Could not read from remote repository.

3
  • thanks for this answer - was there a very recent change to github authentication? ... reason I ask is that I've been using github for 12 mths now without this constant reminder to authenticate but in the past week it now starts to constantly ask me
    – whytheq
    Commented Jun 17 at 11:23
  • @whytheq no recent change in github, as far as I know. May I ask what did bring you to this answer? If you run into one of the messages I quoted, i.e. fatal: '=' does not appear to be a git repository , fatal: Could not read from remote repository., i suspect you updated the remote url of your repo ( git remote set-url ... ) but you maybe put a typo in it.
    – Tms91
    Commented Jun 17 at 14:13
  • i've been using sso to authenticate git to our enterprise github, using vs code as a manager of the repos. Using this method everything has been fine for months - now GCM is constantly asking me to sign-in well every hour or so .... so I've been googling around trying to find possible reasons and saw your answer
    – whytheq
    Commented Jun 17 at 14:33
1

What's wrong

In my case, I realised that my repository was private.

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

Output:

Cloning into 'repo'...
Username for 'https://github.com':
... # and so on. My repository was private.

After publishing, it worked like a charm:

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

Output: Cloning into 'repo'...

How to publish

To make the repository public:

  1. Go to project settings Project settings tab
  2. Scroll down until you see "Danger Zone": Danger Zone
  3. Click "Change visibility":
    Pop-up
  4. Click "I have read and understand these effects", if you really want to publish your repository.
    Button
  5. It may prompt you for password. Enter the password and username and press enter.
  6. Done! Your repository is published now!
0

From GitHub docs:

When Git prompts you for your password, enter your personal access token.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.