Reputation: 37095
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.
Upvotes: 395
Views: 398316
Reputation: 449
From GitHub docs:
When Git prompts you for your password, enter your personal access token.
Upvotes: 0
Reputation: 4214
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.
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
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.
Upvotes: 2
Reputation: 29
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'...
To make the repository public:
Upvotes: 1
Reputation: 3940
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.
Upvotes: 6
Reputation: 815
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
Upvotes: 20
Reputation: 31532
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.
Upvotes: 12
Reputation: 79
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/
Upvotes: 5
Reputation: 803
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.
Upvotes: 35
Reputation: 2865
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
Upvotes: 5
Reputation: 8797
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.
Upvotes: 63
Reputation: 370
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
Upvotes: 16
Reputation: 12914
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
Upvotes: 835