ChatGPT解决这个技术问题 Extra ChatGPT

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
alis@github.com/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://MichaelDrogalis@github.com/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
alis@github.com/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
Look at the comment, which should be posted as an answer. Made it work with 1.7.1, had the missing User/Password prompt problem, too. Props to stackoverflow.com/a/9575906/805284 ...
check the user has read/write access to the repository
In the future, don't paste "Authorization: Basic " when showing example http headers. It's easy to base64 decode that and get your password. @mike: if you haven't changed your github password since you posted this question, I would suggest you do so.
@FlipMcF Thanks man. Was unaware. Password changed.
@Mike NP. Now I get to shamelessly promote a little blog I wrote on it: goo.gl/bpae94

z
zeFree

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:

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


This is often encountered when you clone with the git read-only address (which is the default when you aren't logged in) instead of the read+write ssh address.
My .git/config was more like url=https://github.com/mynickname/my_repo.git But I also changed it like url=ssh://git@github.com/mynickname/my_repo.git and it did the trick
You can change a repo url with git remote set-url command. See my answer below.
or simply change it from the command line using git remote set-url <name> git@github.com:<username>/<repo>.git
For those looking for a non ssh solution, check a few of the other answers here. Adding your username to the https url seems to work. (change config url so that https://@github.com/... is UNAME@github.com/...)
T
Thiago Macedo

To definitely be able to login using https protocol, you should first set your authentication credential to the git Remote URI:

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

Then you'll be asked for a password when trying to git push.

In fact, this is on the http authentication format. You could set a password too:

https://youruser:password@github.com/user/repo.git

You should be aware that if you do this, your github password will be stored in plaintext in your .git directory, which is obviously undesirable.


SSH blocked at work so I have to use HTTPS. Adding the username fixes my issues.
This should be the accepted answer. No reason to manually edit a config file when there's a command line interface to it.
Also, for me, this way (username@github...) asked for password and worked, whereas ssh://git@github... failed expecting public key auth.
@Achint it's an authentication format. You could set your password too https://youruser:password@github.com/user/repo.git despite not secure
Just a note if you have this problem, if you have special characters in the username or password you need to URL encode them. For example, @ needs to be %40.
C
Community

One small addition to Sean's answer.

Instead of editing .git/config file manually, you can use git remote set-url command.

In your case it should be:

git remote set-url origin ssh://git@github.com/derekerdmann/lunch_call.git

I find it easier and cleaner, than messing around with dot-files.

help.github.com: Changing a remote's URL


I don't know if this is just an old post and git has changed, but as today to fix the problem I had to use git remote set-url origin ssh://git@github.com:derekerdmann/lunch_call.git with a colon between the github.com and the repo name
G
Gal Bracha

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://USERNAME@github.com/rootux/my-repo.git

where USERNAME is your github user name


This answer did not apply to my problem. My url in .git/config is set to `github.com/myrepo/subproject'.
Had this problem with Android Studio. Works fine.
My instinct is that this is more along the lines of being the right answer because other solutions either switch to SSH protocol or store password in plaintext.
B
BMB

The other answers that suggest switching to SSH sort of miss the point. HTTPS is supported, but you must log in with you GITHUB password, not your SSH passphrase (which was what was giving me the same exact error).

I was having the same problem, but making sure to use my actual GitHub password at the terminal password prompt fixed the solution with no alteration to the config, or resorting to SSH.

The reason it is important to note this, is many public institutions (such as my school) will block SSH, but allow HTTPS (which is the only reason I started cloning over HTTPS in the first place).

Hope that helps anyone else having the same issue...


but why? I didn't have to do that in the past. Did a certificate expire, or something?
Not sure, I'm not an expert, that's just how I got it to work in my case :)
Same @Thufir. I have no idea why this suddenly worked.
I log on just fine with my username and password on the browser. BUT when i try to git push I am prompted for a u and p and the result is permission denied.... Do you know what I am missing?
A
Andrew Gans

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.

https://i.stack.imgur.com/XzOUh.png

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.


"You may have to check windows credential manager and delete the github entry under control panel > user accounts > credential manager > Windows credentials > Generic credentials " details from this post: stackoverflow.com/a/37450495
L
Laurel

Same error and resolution on Mac OS X.

Everything was working fine till I created a new account on GitHub and tried to push

$ git push -u origin master

And got the error:

remote: Permission to NEWUSER/NEWREPO.git denied to OLDUSER. fatal: unable to access ‘https://github.com/NEWUSER/NEWREPO.git/': The requested URL returned error: 403

It should have fixed by setting the user.name either for global or current repo

$ git config –-global user.name NEWUSER
$ git config user.name NEWUSER

But it didn’t.

I got it fixed by deleting the OLDUSER associated with GitHub from Keychain Access app under Passwords section. Then the push command went successful.

$ git push -u origin master

reference


Deleting the OLDUSER from the Keychain Access App worked for me
I got the same error, but for a different but related reason that required a different solution. I was trying to push to a repo where I don't have write access (I'm not a collaborator). This was more due to my lack of knowledge of how to contribute to a repo that isn't mine. I thought I could just create a new branch and then do a pull request. Not so. I have to fork the repo first, make my changes on the fork, then do a pull request from my forked repo to the original repo. Probably a dumb mistake on my part, but if I can make it, then I'm sure other n00bs could. :)
J
Jeff Hammond

This works for me -:

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

Hope it helps


nice job. set user!
This solution helped with git v1.7 in CentOS 6.10 x86. I was expecting the password promopt to show up (instead of SSH key), and it did (by prepending <username>@ before github.com in remote URL). Thank you!
n
nisah

I think @deepwaters got the answer correct for older versions. The HTTPS URL needs to have the username. I had git 1.7.0.4 and git push origin master wouldn't even ask for a password till I added it.


g
gsf

Upgrade your git. GitHub has answered this question at https://help.github.com/articles/error-the-requested-url-returned-error-403.


It's half the answer, for sure. Other half is what we have here.
N
Nick Veys

A 403 code is "Forbidden". The server saw your request and refused it. Do you have permission to push to that repository?


Me and a friend are having the same problem. The repo is mine, and he can't push. How do we fix this?
how to get persmisson
add your friend into the access list of repo. help.github.jp/enterprise/2.11/user/articles/…
M
Mike

Figured it out. I cloned over HTTPS. Setting up my public SSH keys, cloning over SSH, and pushing over SSH fixed it.


Hmmm... but what when you can't use anything but https, because of a corp firewall, for instance?... According to the github blog, the https access was added to github just for that purpose?
I really don't know. I always clone over SSH now.
Just for posterity (I noticed the timestamp), in regards to filofel's comment: Check out my answer listed above. I have the same restriction you mention, at my school, and found I was supplying the wrong password/passphrase to the terminal prompt. Hope it helps any others with the same issue.
L
Leos Literak

I faced the same error and the cause was stupid - I did not have privileges to commit to selected repository. I did not know that I have to

fork selected project first clone repository locally commit my changes locally push changes to my github clone request pull request to upstream

as described in https://help.github.com/categories/63/articles


Not stupid, this is the correct answer for most first-time contributors to public repositories.
Thanks a lot. Was a first-time contributor to a public repository. This was my issue
A
Akah

I actually had a very simple fix to this. All i did was edit the git config file differently after cloning the repository. The remote origin url is what you need to edit in your default config file. It should look like seen below

[core]
    repositoryformatversion = 0
    filemode = true
    bare = false
    logallrefupdates = true
[remote "origin"]
    fetch = +refs/heads/*:refs/remotes/origin/*
    url = https://*username*@github.com/*username*/*repository*.git
[branch "master"]
    remote = origin
    merge = refs/heads/master

^ this (or any one of its variants below)
Adding the username before github.com fixed it for me.
You are welcome @ÅdəəlÅhmåd . Support the effort by upvoting the answer so that many others can appreciate.
p
prashantitis

Do this for a temporary fix

git push -u https://username:password@github.com/username/repo_name.git master


T
Teepeemm

Click on your repository On the right hand side, click on "Settings" On the left hand side option panel, click on "Collaborators" Add the person name you know in GitHub Click "Add Collaborators"

After this our "Push to Git" worked fine.


J
Juan Sosa

change it from

url=https://MichaelDrogalis@github.com/derekerdmann/lunch_call.git 

to

url=ssh://git@github.com/derekerdmann/lunch_call.git

It works!

Do not forget the "git" before the "@".


It worked for me (using CentOS Server with RStudio behind proxy). Set proxy first : git config --global http.proxy http://proxyUsername:proxyPassword@proxy.server.com:port Then use the command git remote set-url origin to switch the adress.
n
neves

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.

Now add your username to the repo with this command:

git remote set-url origin https://yourusername@github.com/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, try to fork it as a personal repo to debug any auth problem.


C
Community

For those having permission denied 403 error while using ssh(according to Xiao) or http urls try these commands

>git config --global --unset-all credential.helper

>git config --unset-all credential.helper

with administrator rights

>git config --system --unset-all credential.helper

Now every time Git will ask for login and password. Save them through git config --global credential.helper store.
C
CKM

None of the above answers worked for my enterprise GitHub account. Follow these steps for pushing via ssh key generation way.

Create a repo by visiting your git account.

Generate ssh key:

ssh-keygen -t rsa -C "your_email@example.com"

Copy the contents of the file ~/.ssh/id_rsa.pub to your SSH keys in your GitHub account settings. Test SSH key:

ssh -T git@github.com
clone the repo:
git clone git://github.com/username/your-repository

Now cd to your git clone folder and do:

git remote set-url origin git@github.com:username/your-repository.git

Now try editing a file (try the README) and then do:

git add -A
git commit -am "my update msg"
git push -u origin master

Update: new git version seems to recommend not to have any file while new repo is created. Hence make aa blank repo.


This answer helped me, but you must be sure that your keys have default names like id_rsa and id_rsa.pub, otherwise, you will continue to get the error Permission denied (publickey,keyboard-interactive). fatal: The remote end hung up unexpectedly. So either rename your key to the default name or use this answer to clarify how to set a custom path to ssh key.
K
Kapil Soni

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.


s
sailfish009

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.


A
Andrew Lygin

What worked for me:

My repo was a fork and still linked to the the parents repo.

git remote -v

Will tell you if it is your repo or not.

git remote set-url origin https://github.com/USERNAME/OTHERREPOSITORY.git

Allows you to reconfigure it to your repo and then allow you to push.


p
patcon

For anyone curious, my mac machine vs lucid vm ran git 1.7.6 vs 1.7.0.4, and the exact same repo was pushable from my mac (newer git) but not the VM

Same curl version. Perhaps some older git versions don't support https pushes?


Yes, https push to github works here (even through proxy with password). I use git 1.7.3. For me, it failed first because I typed the wrong password.
It works for me with git 1.7.1, but there is one thing you have to pay attention too (and that was what I missed in my first try): Give the user name in the HTTPS-URL, i.e. url=https://username@github.com/username/repo.git
T
Tunaki

Add the user name as part of the URL and This error happens because the git command is hitting http instead of https. So set the url

git remote set-url origin https://<username>@github.com/Path_to_repo.git

After which you will be prompted for password:


F
Faisal

Try below command using administrator permission. This command solved my issue. Hope it will resolve your problem.

git config --system --unset-all credential.helper

This command reset all user credentials. And let user to give user id and token again. For my case issue resolve by doing this. I was logged in another git account.
L
Lucas Ou-Yang

I figured out my own variation of this problem.

The issue was not changing the protocol from https to ssl, but instead, setting the Github global username and email! (I was trying to push to a private repository.

git config --global user.email "your_github_email_@email.com"

git config --global user.name "Your full name"

Does not work for me. Config has been set, use github.com.. with no '@' in it
A
AndyL

Github has page dedicated to troubleshooting this error:

https://help.github.com/articles/https-cloning-errors

In my case it turned out that using a new version of git (1.8.5.2) solved this problem.


M
Mehrdad

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.