15

I want to push README.md to Github.
Using Ubuntu 14.04LTS
So, I commit in the following steps.

echo "# test" >> README.md
git init
git add README.md
git commit -m "first commit"
git remote add origin https://github.com/user/repo.git
git push -u origin master

But, below error occurred.

error: The requested URL returned error: 403 Forbidden while accessing https://github.com/user/repo.git/info/refs

fatal: HTTP request failed

I know solve this error this way

git remote set-url origin https://username@github.com/user/repo.git

In this way , I must enter password.

$ git push origin master
Password: 

But I hate to enter password.

I have checked this, but I don't solved.
Pushing to Git returning Error Code 403 fatal: HTTP request failed

Please tell me how to push without password.

Community
  • 1
  • 1
technuma
  • 303
  • 1
  • 3
  • 13

8 Answers8

12

This may solve your problem:

git remote set-url origin https://username:userpwd@github.com/user/repo.git
Yusuf K.
  • 4,195
  • 1
  • 33
  • 69
dilei
  • 121
  • 1
  • 4
  • @JanDoggen This is not a link-only answer, if you look closer to answer, you see that dilei gives the answer of question not a link. – Yusuf K. Apr 06 '16 at 20:58
  • @Yusuf Got it. And (s)he should still explain *why* this may solve the problem. 'Code only' answer are also valued low on this site. – Jan Doggen Apr 07 '16 at 07:30
  • @JanDoggen 403 error means authorization issue, so this answer send username and password on remote url and there is no more 403 error for that. – Yusuf K. Apr 07 '16 at 07:35
  • Gleeful bashing of budding new user aside **this and nothing else** is what worked for me. However, this will cause your password to be stored **in plain text** in your .git directory. I suggest setting remote URL to `https://username@github.com/user/repo.git`, and using more suitable means to cache your password if desired. This issue occurred for me after changing my github username. I can't for the life of me find a way to change the password git tried to use for the remote, but *dilei's answer works*. – John Apr 27 '16 at 09:42
  • yeah +1 on this fixing my problem. .git-credentials was being ignored for me on whatever git version is on this centos6 box, and this fix allowed me to get on with it. entirely enough information here to be usable. – lamont Dec 05 '17 at 21:24
6

You have to either use https and enter your password or use ssh (and associate your public ssh key to your github account)

Fernando
  • 1,382
  • 8
  • 17
  • thank you for answering. why I can't use https without password? Until a little while ago, I can use https without password. – technuma Jan 17 '15 at 05:13
  • You can pull from https without password if you clone a repo as read-only (i.e without username), but you can't push to a https repo without password unless you use password catching: https://help.github.com/articles/why-is-git-always-asking-for-my-password/ – Fernando Jan 17 '15 at 05:21
  • Thank you verymuch. Probably, I can’t push from multiple devices. Because , I need do this git remote add origin https://username@github.com/user/repo.git Probably,I can't push this remote git remote add origin https://github.com/user/repo.git – technuma Jan 17 '15 at 05:25
  • If you use a ssh remote you need to add the public key of each user in each device in order to push. If you use https you don't have to do that but you will have to enter the password (at least once per session if you use a cache with a long timeout). – Fernando Jan 17 '15 at 05:47
  • how to do you the things in ur answer? Can you provide some code or commands to execute? – Charlie Parker Jan 28 '16 at 16:55
  • Check the set-url option on the question @CharlieParker – Fernando Feb 04 '16 at 13:45
4

I believe one of the main reasons of this happening is because of bad login credentials from your local machine to the server.

If I remember correctly, one has to

(1) Make sure you have a stable git version

(2) Ensure the remote is correct

(3) Provide access token if 2FA is enabled

(4) Checking your permissions(username/password)

(5) Use ssh instead of https

Pushing to Git returning Error Code 403 fatal: HTTP request failed might come in handy, which has a lot of extra information regarding your problem.

Dharman
  • 30,962
  • 25
  • 85
  • 135
Joey Dorrani
  • 247
  • 1
  • 1
2

If you're using multiple github accounts then that could also be the cause of the problem. Git saves the username and password you use first in your OS's credential vault. Any subsequent requests will be using those details regardless of what your IDE tells you.

Prof
  • 657
  • 1
  • 14
  • 24
2

If your problem is the result of a changing a repo (resulting in a username, password mismatch), try this at the command line:

git credential-osxkeychain erase
host=github.com
protocol=https
[Press Return]

it will prompt you for your username and password.

See https://help.github.com/articles/updating-credentials-from-the-osx-keychain/

Cartesian Theater
  • 1,920
  • 2
  • 29
  • 49
1

If you're working with a clone or fork, double-check that the repository URL you're trying to push to is your fork's URL instead of the original owner's repository URL.

git remote -v
Paul Roub
  • 36,322
  • 27
  • 84
  • 93
Bruce Seymour
  • 1,520
  • 16
  • 24
1

I faced the same error

Error: The requested URL returned error: 403 while accessing

For example: https://github.com/Joey-project/repo.git/info/refs fatal: HTTP request failed

and then resolved it by the following method:

  1. Go to Control Panel
  2. Open User Accounts
  3. Open Credentials Manager
  4. Open Windows Credentials

Now in the Generic Credentials Tab see the GitHub/(any other host) credentials then edit your username and/or password to their correct states.

LightCC
  • 9,804
  • 5
  • 52
  • 92
0

Just update your git client and you should not get this issue anymore

ggonzal
  • 129
  • 1
  • 3