Mike
Mike

Reputation: 19737

Pushing to Git returning Error Code 403 fatal: HTTP request failed

I was able to clone a copy of this repo over HTTPS authenticated. I've made some commits and want to push back out to the GitHub server. Using Cygwin on Windows 7 x64.

C:\cygwin\home\XPherior\Code\lunch_call>git push
Password:
error: The requested URL returned error: 403 while accessing https://MichaelDrog
[email protected]/derekerdmann/lunch_call.git/info/refs

fatal: HTTP request failed

Also set it up with verbose mode. I'm still pretty baffled.

C:\cygwin\home\XPherior\Code\lunch_call>set GIT_CURL_VERBOSE=1

C:\cygwin\home\XPherior\Code\lunch_call>git push
Password:
* Couldn't find host github.com in the _netrc file; using defaults
* About to connect() to github.com port 443 (#0)
*   Trying 207.97.227.239... * 0x23cb740 is at send pipe head!
* Connected to github.com (207.97.227.239) port 443 (#0)
* successfully set certificate verify locations:
*   CAfile: C:\Program Files (x86)\Git/bin/curl-ca-bundle.crt
  CApath: none
* SSL connection using AES256-SHA
* Server certificate:
*        subject: 2.5.4.15=Private Organization; 1.3.6.1.4.1.311.60.2.1.3=US; 1.
3.6.1.4.1.311.60.2.1.2=California; serialNumber=C3268102; C=US; ST=California; L
=San Francisco; O=GitHub, Inc.; CN=github.com
*        start date: 2011-05-27 00:00:00 GMT
*        expire date: 2013-07-29 12:00:00 GMT
*        subjectAltName: github.com matched
*        issuer: C=US; O=DigiCert Inc; OU=www.digicert.com; CN=DigiCert High Ass
urance EV CA-1
*        SSL certificate verify ok.
> GET /derekerdmann/lunch_call.git/info/refs?service=git-receive-pack HTTP/1.1
User-Agent: git/1.7.4.3282.g844cb
Host: github.com
Accept: */*
Pragma: no-cache

< HTTP/1.1 401 Authorization Required
< Server: nginx/1.0.4
< Date: Thu, 15 Sep 2011 22:44:41 GMT
< Content-Type: text/plain
< Connection: keep-alive
< Content-Length: 55
< WWW-Authenticate: Basic realm="GitHub"
<
* Ignoring the response-body
* Expire cleared
* Connection #0 to host github.com left intact
* Issue another request to this URL: 'https://[email protected]/dereker
dmann/lunch_call.git/info/refs?service=git-receive-pack'
* Couldn't find host github.com in the _netrc file; using defaults
* Re-using existing connection! (#0) with host github.com
* Connected to github.com (207.97.227.239) port 443 (#0)
* 0x23cb740 is at send pipe head!
* Server auth using Basic with user 'MichaelDrogalis'
> GET /derekerdmann/lunch_call.git/info/refs?service=git-receive-pack HTTP/1.1
Authorization: Basic XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
User-Agent: git/1.7.4.3282.g844cb
Host: github.com
Accept: */*
Pragma: no-cache

< HTTP/1.1 401 Authorization Required
< Server: nginx/1.0.4
< Date: Thu, 15 Sep 2011 22:44:41 GMT
< Content-Type: text/plain
< Connection: keep-alive
< Content-Length: 55
* Authentication problem. Ignoring this.
< WWW-Authenticate: Basic realm="GitHub"
* The requested URL returned error: 401
* Closing connection #0
* Couldn't find host github.com in the _netrc file; using defaults
* About to connect() to github.com port 443 (#0)
*   Trying 207.97.227.239... * 0x23cb740 is at send pipe head!
* Connected to github.com (207.97.227.239) port 443 (#0)
* successfully set certificate verify locations:
*   CAfile: C:\Program Files (x86)\Git/bin/curl-ca-bundle.crt
  CApath: none
* SSL re-using session ID
* SSL connection using AES256-SHA
* old SSL session ID is stale, removing
* Server certificate:
*        subject: 2.5.4.15=Private Organization; 1.3.6.1.4.1.311.60.2.1.3=US; 1.
3.6.1.4.1.311.60.2.1.2=California; serialNumber=C3268102; C=US; ST=California; L
=San Francisco; O=GitHub, Inc.; CN=github.com
*        start date: 2011-05-27 00:00:00 GMT
*        expire date: 2013-07-29 12:00:00 GMT
*        subjectAltName: github.com matched
*        issuer: C=US; O=DigiCert Inc; OU=www.digicert.com; CN=DigiCert High Ass
urance EV CA-1
*        SSL certificate verify ok.
* Server auth using Basic with user 'MichaelDrogalis'
> GET /derekerdmann/lunch_call.git/info/refs HTTP/1.1
Authorization: Basic xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
User-Agent: git/1.7.4.3282.g844cb
Host: github.com
Accept: */*
Pragma: no-cache

* The requested URL returned error: 403
* Expire cleared
* Closing connection #0
error: The requested URL returned error: 403 while accessing https://MichaelDrog
[email protected]/derekerdmann/lunch_call.git/info/refs

fatal: HTTP request failed

These are the versions of git and curl that I have:

C:\Users\XPherior>git --version
git version 1.7.4.msysgit.0

C:\Users\XPherior>curl --version
curl 7.21.7 (amd64-pc-win32) libcurl/7.21.7 OpenSSL/0.9.8r zlib/1.2.5
Protocols: dict file ftp ftps gopher http https imap imaps ldap pop3 pop3s rtsp
smtp smtps telnet tftp
Features: AsynchDNS GSS-Negotiate Largefile NTLM SSL SSPI libz

Upvotes: 849

Views: 1550876

Answers (30)

Rolf
Rolf

Reputation: 1199

It could be that you have stored (cached) credentials from another repo and git tries to authenticate using the wrong credentials. Run this to clear the cache and then retry again.

git credential-cache exit

See https://git-scm.com/docs/git-credential-cache#_controlling_the_daemon

Upvotes: 0

neves
neves

Reputation: 39433

A lot of answers here, but this is what solved my problem.

Since July 2020 you must use Token authentication to access GitHub if you are using HTTPS.

So you must generate an access token in your profile settings page and use it as your password. Check the boxes necessary to write to the repository.

Now add your username to the repo with this command:

git remote set-url origin https://[email protected]/user/repo.git

When you try to push, it will ask for your password. Enter your newly generated token.

If you are still having trouble pushing, use the web interface to fork it as a personal repo to isolate any permission problem. You'll be able to focus on solving the auth problem.

Upvotes: 22

Vikrant Singh Rawat
Vikrant Singh Rawat

Reputation: 119

I faced the same issue The requested URL returned error: 403 in android studio.

I have followed the below steps:-

  1. Right-click in project name ---> git ----> add
  2. After that open one dialog ----> Enter generate the by GitHub.
  3. Then Write the Commit message ----> And Select the Push option.

Note:- So you must generate an access token in your profile settings page and use it as your password.

Upvotes: 0

Nico
Nico

Reputation: 1838

I faced similar issue and most of the answer did not work in my case, i was getting permission denied 403 forbidden error. Following steps helped me to resolve the issue:

Install git CLI by below command if you have brew installed:

brew install gh

Reference to install git CLI https://github.com/cli/cli#installation

then run

gh auth login  

it will ask you following questions, answer like this,

What account do you want to log into? GitHub.com
? What is your preferred protocol for Git operations? HTTPS
? Authenticate Git with your GitHub credentials? Yes
? How would you like to authenticate GitHub CLI? Login with a web browser

It will generate code for you, enter generated to code your browser for authentication.

! First copy your one-time code: 14*B-E2*7

Press Enter to open github.com in your browser... 
✓ Authentication complete.

By following above steps you will be able to push code to your repository.

Upvotes: 6

Jo&#227;o Matos
Jo&#227;o Matos

Reputation: 7020

Just to add one more scenario that happened to me, my company requires SSO hence when I created/renewed my new publishing token I forgot to authorize it and started to get these 403 responses from github:

enter image description here

enter image description here

I suspect this distraction might be common

Upvotes: 1

Relie Essom
Relie Essom

Reputation: 1378

If no other methods worked, try this:

  • McOS only
  1. Go to Finder, search for the Keychain Access.
  2. While in Keychain Access, search for github.com.
  3. Then look for internet password double click that.
  4. Once double clicked, look for show password then enter your computer password to access it.
  5. You should now be able to edit or delete the current token. After you've edited the token or deleted it save your changes and you should be able to push your code.

Hope this helped.

Upvotes: 0

Megha Dandapat
Megha Dandapat

Reputation: 81

The support for password authentication while accessing Github from CLI(Command Line Interface) has been removed on August 13, 2021 by replacing them with personal access token.

Steps to create personal acess token

By default tokens always include read-only access to all public repositories on GitHub. Hence, to give push or pull and rights you need to select the appropriate "Scope" while generating the access token.

The scope for public repositories is public_repo, and for private repositories is repo. A token with one of those scopes is the most limited access possible for Git push or pull access.

Now, when you are prompted for your username and password, provide your GitHub username and the access token in place of the password.

For the description of other available scopes refer the Github Documention

Upvotes: 1

Md Rehan
Md Rehan

Reputation: 363

For windows Go to "Control Panel\User Accounts\Credential Manager" and remove the entry shown in the figure and push with username/password.

Credential Manager

Upvotes: 2

Xiao
Xiao

Reputation: 12705

I just got the same problem and just figured out what's cause.

Github seems only supports ssh way to read&write the repo, although https way also displayed 'Read&Write'.

So you need to change your repo config on your PC to ssh way:

  1. Edit .git/config file under your repo directory.
  2. Find url=entry under section [remote "origin"].
  3. Change it from:
    url=https://[email protected]/derekerdmann/lunch_call.git
    to:
    url=ssh://[email protected]/derekerdmann/lunch_call.git
    That is, change all the texts before @ symbol to ssh://git
  4. Save config file and quit. now you could use git push origin master to sync your repo on GitHub.

Upvotes: 1020

sailfish009
sailfish009

Reputation: 2927

if you get 403 error with github,

sure to check all checkboxs when create token:

https://github.com/settings/tokens

i think github token generate page has design flaw.

Upvotes: 5

Sadheesh
Sadheesh

Reputation: 893

I faced similar error

fatal: unable to access 'https://gitlab.com/xxxx/yyyy.git/': The requested URL returned error: 403

I resolved by switching network, ( by changing IP). initially, I faced an issue in my system, then I tried with new network (by using a mobile hotspot) and did a git pull,

again I moved back to the primary network, and i was able to perform all git operations with no issues.

Upvotes: 0

Ausrada404
Ausrada404

Reputation: 599

If SSH is not allowed for some reason, HTTPS is also ok.

To push the commits by HTTPS, you should use the personal access token and make sure the read and write is available in Scopes which define the access for personal tokens.

Setting in GitHub as follows.

enter image description here

Upvotes: 4

Naveen Perpaga
Naveen Perpaga

Reputation: 31

I had solved this issue of Permission denied by just:

1.) upgrading the git to latest version.

2.) Changing remote url to the format "https://[email protected]/username/repo_name.git" through command entered in git-bash "git remote set-url origin https://[email protected]/username/repo_name.git"

Previously, I was using the version 2.28 so I was not getting the Login Screen Prompt. Also by changing the url I was able to login with git-hub credentials and push the changes to the repo

Upvotes: 1

Muhammad Numan
Muhammad Numan

Reputation: 249

This error happened when we clone someone repository from github. this might easily be solve by updating origin by using

git remote set-url origin 'Your repository origin'

then after this apply

git push -f origin master

This might be very helpful for all

Upvotes: 0

Gal Bracha
Gal Bracha

Reputation: 20021

Edit .git/config file under your repo directory

Find url= entry under section [remote "origin"]

Change it from url=https://github.com/rootux/my-repo.git to https://[email protected]/rootux/my-repo.git

where USERNAME is your github user name

Upvotes: 68

ARHAM RUMI
ARHAM RUMI

Reputation: 543

I faced the same problem and noticed that the repository I was trying to push my branch was private. So, try the following procedure:

  1. Make sure you have access to that private repository

  2. Fork the repository first. You will notice that the repository URL will contain your GitHub username

  3. Clone it now like this --> git clone https://github.com/your-github-username/example-repository.git

  4. Enter in the cloned repository folder --> cd repository-directory

Do whatever you want to do with your cloned repository. Staying in the same cloned repository directory move to the next steps

  1. Check all the branches. This will list up the available branches --> git branch

  2. Create your branch now --> git checkout -b your-branch-name

  3. Run git branch to check if your branch is created

  4. Now run this command --> git add .

  5. Commit your changes --> git commit -m "your message"

  6. Push your branch --> git push origin your-branch-name

  7. Check GitHub site to make sure your branch is pushed now

That's All

Upvotes: 0

Ashandra Singh
Ashandra Singh

Reputation: 198

I am using a Mac and got the error fatal: unable to access The requested URL returned error: 403.

I did change my GitHub account details.

I had to edit my keychain entry for GitHub and update the username to the new username. You can easily find KeyChain in the top search of the MAC.

Upvotes: 0

Rushikesh Welkar
Rushikesh Welkar

Reputation: 153

Make git repository from private to public.

Upvotes: 1

Mehrdad
Mehrdad

Reputation: 1208

Anyone who didn't solve their problem with these solutions follow this thread:

"This happens when two git accounts are being used on same machine" https://stackoverflow.com/a/52046047/7861886

it has Windows solution and also i have added Mac solution for Mac users in comments.

Upvotes: 2

Rajneesh Shukla
Rajneesh Shukla

Reputation: 1382

I am having same issue. None of the above works for me. The problem is Github has block my write permission. I have changed my password. Now I am able to push.

Upvotes: 0

Kapil Soni
Kapil Soni

Reputation: 1051

Below is the solution

For Windows you can find the keys here:

control panel > user accounts > credential manager > Windows credentials > Generic credentials

Next, remove the Github keys.

In mac

1-In Finder, search for the Keychain Access app.

2In Keychain Access, search for github.com.

3-Find the "internet password" entry for github.com.

4-Edit or delete the entry accordingly.

Upvotes: 7

Vadim Zhuk
Vadim Zhuk

Reputation: 393

  1. Check if you are on the correct branch git status
  2. Check your repository permissions (write permission is needed)

Upvotes: 0

Andrew Gans
Andrew Gans

Reputation: 750

If you are using windows, sometimes this may happen because Windows stores credentials for outer repo (in our case github) in its own storage. And credentials that saved there can be different from those you need right now.

enter image description here

So to avoid this problem, just find github in this storage and delete saved credentials. After this, while pushing git will request your credentials and will allow you to push.

Upvotes: 49

MG KYAING
MG KYAING

Reputation: 51

This 403 Error (Access denied) can occur when you haven't accepted the invite link in your email or github repo account.

After you click invitation link, you can add remote repo with following commands:

git remote add <name> <url>
git push —set-upstream <repo_name> master

Example:

git remote add ProgrammingFoundationExam https://github.com/itprowhoami/ProgrammingFoundationExam.git
git push --set-upstream ProgrammingFoundationExam master

Upvotes: 0

Ruan
Ruan

Reputation: 4293

If All else fails. Just make sure you didn't Archive your project. That was my problem, puts the whole solution in a read only mode.

Upvotes: 0

Mohammed Fathi
Mohammed Fathi

Reputation: 1475

This has happened to me because the repository was disabled (a repository can be disabled by the owner or Github may disable all private repositories of an account if the account does not pay it's bill).

So you should contact the repository owner and inform him that the repository is disabled.

Upvotes: 0

Roddy P. Carbonell
Roddy P. Carbonell

Reputation: 865

I don't know whether someone has mentioned this before or not.

I was having this problem with Bitbucket, and I noticed one thing. If you have this, for example,

git push https://myrepo:[email protected]/myrepo/myrepo.git --all

Notice the @ in there, right after the password. See, if your password ends with a @, you'd have two @@ instead of one. In my case, it was the password that was causing the issue.

Upvotes: 0

Seyed Morteza Kamali
Seyed Morteza Kamali

Reputation: 846

I had this problem because I had proxy I couldn't access to my repository

C:\Users\YourUser\.gitconfig

remove bullshit proxy and it should work

enter image description here

then try again to clone by gitbash

 git clone http://********************

enter image description here

Upvotes: 0

Mahesh Jamdade
Mahesh Jamdade

Reputation: 20369

make sure you have enough permissions to push to the repository if you do then try running these commands

git config --global user.email youremail@domain.
git config --global user.name username
git config --global user.password yourpassword

hope this helps someone

Upvotes: 0

anil
anil

Reputation: 464

Provide write access for the user.

After providing the access.Pull the code once and then push it.

Upvotes: 0

Related Questions