0

I am trying to push some modifications into a git repository, but get the message: "I get the fatal: unable to access 'repository': The requested URL returned error: 403

Allow me to give you a few more details:

  1. I work on Linux Ubuntu, 20.04.3 LTS

  2. I use my PAT which I recently generated as a password. (I am pretty sure it is fine, because it doesn't give me the Authentication failed error.

  3. In my .bashrc file, I have the following lines:

git config --global user.name  "Niceno"
git config --global user.email "bojan.niceno.scientist@gmail.com"

which are both correct, and have been working for several years now.

  1. The .git/config reads:
[core]
    repositoryformatversion = 0
    filemode = true
    bare = false
    logallrefupdates = true
[remote "origin"]
    url = https://github.com/DelNov/T-Flows
    fetch = +refs/heads/*:refs/remotes/origin/*
[branch "development_branch"]
    remote = origin
    merge = refs/heads/development_branch

which doesn't tell me much. 5. If I log in in the Git account DelNov, to which I have admin rights, I see that the user Niceno, my humble me, is granted access to repository.

I am really baffled, because I am trying to do something which I was doing for years. Yet all of a sudden, I can't do a simple push.

Any advice would be appreciated.

Bojan Niceno
  • 113
  • 1
  • 1
  • 11
  • You can't push, but can you do other actions such as pull? – git_gud Dec 14 '21 at 13:30
  • Just a quick reminder, before making a push you should make an update and a commit. Also another reason why such issues can occur is that your git project might have a previous Github repository and you have in that case to override those previous credentials. It may also be a temporary issues, and in that case you may just retry later. – Himmels DJ Dec 14 '21 at 13:44
  • @SOROMEED: Yes, I can perform pull. It tells me all is up to date because I cloned just just a few minutes ago, changed one file and tried if I can do the push. – Bojan Niceno Dec 14 '21 at 13:47
  • @HimmelsDJ: I did the commit and, as I wrote to SOROMEED, I did the clone just a few minutes ago. – Bojan Niceno Dec 14 '21 at 13:48
  • Are you 100% positive that you have the right to push on that repo and/or branch? – git_gud Dec 14 '21 at 13:50
  • Ok if so then it's likely a git origin issue, I mean the push you make is likely forwarding to another repository. – Himmels DJ Dec 14 '21 at 14:08
  • @SOROMEED: I just double checked, I am among the users who can contribute to that repository. I am trying to attach a screenshot, but seem to be unable to in this comment. – Bojan Niceno Dec 14 '21 at 14:21
  • I tried to do the same from another computer in a different network, and faced the same issue. @HimmelsDJ: how do I check if pushes go to a different repository? – Bojan Niceno Dec 14 '21 at 14:43
  • Apparently just anyone can *read* `https://github.com/DelNov/T-Flows` (I just did, in a browser). Your 403-forbidden suggests that your credential helper is supplying the wrong user name and/or PAT. Note that 403 *is* "authentication failed", in this case. – torek Dec 14 '21 at 19:08
  • @torek: I am pretty sure I have write access. If I open a file from the repository in a browser, logged in as myself, I can edit files directly. I am really clueless, it never happened to me and I am regularly using git for several years now. Did something change recently on Github, like in the last couple of months? – Bojan Niceno Dec 15 '21 at 15:42
  • They went to PAT-only: if they think what you're sending them is a password, they reject it. How they decide some string is a PAT and not a password, I don't know (perhaps some sort of checksum or type signature at the front?). (For my own part, I always use ssh instead of https to write to GitHub.) – torek Dec 16 '21 at 00:32

2 Answers2

1

I read your explanation and I hope this is what to did:

  1. git add.
  2. git commit -m "My first commit"
  3. git push https://username:password@github.com/username/repository.git --all

From the comments I understand that this is the first push of this project to the repository. So in this case it's advisable to set the full url https://username:password@github.com/username/repository.git --all instead of just doing git push origin --all.

I understand the fact that you were used to the git command lines but just in case you forgot some things this link will strongly help you as well

UPDATE:

I cloned and push the project base on the github url you provided in the comment. After doing this:

$ git remote add origin git@github.com:username/new_repo

Make sure you've clicked on the "copy" icon that is at right end of the repository's url from you github account to grab your real this ( git@github.com:username/new_repo ) without blank spaces added. Doing that I received a notification as the folder is empty ( Not a problem). Then I did:

$ git push -u origin master

And there came a fatal error, a rejection for push. But to force push I did:

$ git push -f origin

This gave a clue of the rejection it was about, then to force push the project and bypass the rejection I did this with my github account opened on browser on the same system:

$ git push --set-upstream origin main

And the push was successful. About the process to add an existing project to a new github repository take a look at this link

and take a look at the part that says "A new repo from an existing project" to make sure you started well. But if you do :

$ git push --set-upstream origin main

you should be able to get rid of the 403 rejection. But you might be connected to your github account on the system you're pushing with.

Himmels DJ
  • 395
  • 5
  • 20
  • Thanks, I tried that, but also without success. I get the same error as before: remote: Permission to DelNov/T-Flows.git denied to Niceno. fatal: unable to access 'https://github.com/DelNov/T-Flows.git/': The requested URL returned error: 403 In the meanwhile I also removed user Niceno from DelNov/T-Flows and invited him back as a contributor. It was to no avail. – Bojan Niceno Dec 15 '21 at 14:47
  • I cloned and pushed successfully the project from the url you gave. Take a look at the update I made in answer. – Himmels DJ Dec 17 '21 at 01:25
  • thanks a lot for your help. In the meanwhile I seem to have found a different workaround. I created a new PAT with all check boxes which appear on the page for updating PAT checked. That also resolved the issue. – Bojan Niceno Dec 17 '21 at 06:33
  • Ok, great then ! – Himmels DJ Dec 17 '21 at 12:18
0

Go to your local repository folder and find a hidden folder called ".git". find a file called "config" in the folder as attached below.
enter image description here

You need to change the url = https://github.com/... to SSH url that can find from GitHub repository(on git hub Web portal) cone menu as below picture.

enter image description here

This is what the config file looks like, after the change of the url. enter image description here

This solved my issue. I believe this will help.