372

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 git@github.com
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.

Kit Sunde
  • 35,972
  • 25
  • 125
  • 179

10 Answers10

789

Don't use HTTP use SSH instead

change

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

to

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

you can do it in .git/config file

Hugo
  • 12,334
  • 6
  • 30
  • 36
  • 1
    Thanks! I just figured this out after reading http://stackoverflow.com/a/10126412/29347, I don't think github normally gives me a repo remote as HTTPS which caused some confusion. – Kit Sunde Jun 06 '12 at 06:41
  • 2
    You can change this option by clicking the button where you copy your clone url. – Derek Adair Dec 16 '14 at 02:57
  • For MacOS. Issue when you upgrade to lastest macos. http://stackoverflow.com/a/39616339/1445102 – 1Rhino Dec 26 '16 at 04:31
  • 20
    You can also do `git remote set-url origin git@github.com:user/repo.git`, as detailed in https://stackoverflow.com/questions/10126381/why-does-github-keep-asking-me-for-repo-credentials/10126412#10126412 – And Finally Jun 28 '18 at 11:03
  • 1
    "git config --global credential.helper store" solved it for me, even if this may include security issues. – Thomas Schütt Sep 10 '21 at 09:35
  • In my case, it happens when I download packages or releases. I'm using Xtreme Downloader, and it asks for username and password. However, when I'm using ADM in android, it fails with 128 status code. – Habibullah Rezaie May 13 '22 at 12:05
  • 1
    don't forget `git remote set-url --push origin git@github.com:user/repo.git` in addition to `git remote set-url origin git@github.com:user/repo.git` – Delphine Jul 19 '22 at 14:32
62

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.

Dherik
  • 17,757
  • 11
  • 115
  • 164
Sean
  • 8,407
  • 3
  • 31
  • 33
  • 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 Feb 28 '13 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.

Community
  • 1
  • 1
Catalin Hritcu
  • 793
  • 7
  • 12
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:password@github.com/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:token@github.com/WEMP/project-slideshow.git
Hugh
  • 11
  • 3
kaushal
  • 785
  • 12
  • 27
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://github-username@github.com/WEMP/project-slideshow.git
IanI
  • 370
  • 3
  • 9
  • 8
    You don't have to remove the remote. You can just change the URL: `git remote set-url origin https://github-username@github.com/WEMP/project-slideshow.git` – shovavnik Dec 23 '13 at 10:59
9

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.
a paid nerd
  • 30,702
  • 30
  • 134
  • 179
  • 2
    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 Oct 27 '17 at 04: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.

jdhao
  • 24,001
  • 18
  • 134
  • 273
jochen
  • 3,728
  • 2
  • 39
  • 49
  • 1
    The URL has been updated: https://help.github.com/articles/caching-your-github-password-in-git – MarkHu Apr 02 '16 at 07:04
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

Hazarapet Tunanyan
  • 2,809
  • 26
  • 30
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/

Neil
  • 79
  • 1
  • 4
2

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!