86

Recently, I'm added as a member/contributor for Github project. I have cloned that project on local machine.

I have made some changes and committed locally and now trying to Push changes to original repo but when I try to Push,I get some permission error?

C:\Users\MM\Documents\GitHub\software-licensing-php [master]> git push
origin master
remote: Permission to EasySoftwareLicensing/software-licensing-php.git denied to
 irfandayan.
fatal: unable to access 'https://github.com/EasySoftwareLicensing/software-licen
sing-php.git/': The requested URL returned error: 403
C:\Users\MM\Documents\GitHub\software-licensing-php [master]> git statu
s
# On branch master
# Your branch is ahead of 'origin/master' by 2 commits.
#   (use "git push" to publish your local commits)
#
nothing to commit, working directory clean

Am I lacking some permission for pushing changes so I could ask the original author of project?

Irfan
  • 4,882
  • 12
  • 52
  • 62

10 Answers10

168
  • click fork button on original github project page
  • clone your forked repository instead original
  • push to it
  • press Pull Requests button on your repository
  • create it
  • wait for original author to accept it
cnd
  • 32,616
  • 62
  • 183
  • 313
  • I just fork, clone, commit and push the changes and generated pull request on that forked project and I can see it in pull requests. Will the original author receive notification for this pull request? – Irfan Jul 25 '13 at 12:23
  • 1
    Yes, sure he will be forced to review it :) but you must create pull request by yourself and say what and why you changed so it will be easy for author to review. – cnd Jul 25 '13 at 12:26
  • 1
    What if he added me as a collaborator, what is process then? – tu4n Oct 08 '16 at 04:05
  • @Cyanide Thank you a lot! I was trying to push into original fork too. – zored May 03 '17 at 21:37
  • 1
    In case you already cloned the original git hub project you don't have to clone again the forked one. Only update url settings in .git config file. – Lukáš Kmoch Nov 10 '17 at 13:53
87

I used to have the same error when i change my user email by git config --global user.email and found my solution here: Go to: Control Panel -> User Accounts -> Manage your credentials -> Windows Credentials

Under Generic Credentials there are some credentials related to Github, Click on them and click "Remove".

and when you try to push something, you need to login again. hope this will be helpful for you

Luan Si Ho
  • 1,438
  • 2
  • 13
  • 17
36

In could able to resolve this issue with giving username and password in below url.

Please replace username and password with your Github credentials:

git remote set-url origin https://<username>:<password>@github.com/<username>/FirstRepository.git
null
  • 3,959
  • 1
  • 21
  • 28
Srinivas Narula
  • 499
  • 4
  • 7
  • what is the difference between this line of code and `git config --global user.name "your username" git config --global user.password "your password"` – Michael Mulik Jun 29 '20 at 13:44
  • So above method was more handy and dont remember why didn't use git config. – Srinivas Narula Jun 30 '20 at 16:30
  • Now (2022-06-30) in your config files edit the PAT every now and then `url = https://you:personalaccesstoken@github.com/you/repo.git` – Huub Jun 30 '22 at 13:20
11

For some reason my push and pull origin was changed to HTTPS-url in stead of SSH-url (probably a copy-paste error on my end), but trying to push would give me the following error after trying to login:

Username for 'https://github.com': xxx
Password for 'https://xxx@github.com': 
remote: Invalid username or password.

Updating the remote origin with the SSH url, solved the problem:

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

Hope this helps!

mlunoe
  • 4,422
  • 4
  • 32
  • 43
  • that's the most recent and working method if you want to use separate accounts sharing same machine(key) – SomeUser Jun 12 '23 at 18:38
6

See the github help on cloning URL. With HTTPS, if you are not authorized to push, you would basically have a read-only access. So yes, you need to ask the author to give you permission.

If the author doesn't give you permission, you can always fork (clone) his repository and work on your own. Once you made a nice and tested feature, you can then send a pull request to the original author.

Shahbaz
  • 46,337
  • 19
  • 116
  • 182
  • That link doesn't say (as of June 6 2016) that author's permission is required when pushing over HTTPS. Only that your github username and password will be required. HTTPS is actually the recommended cloning method according to that page – BeetleJuice Jun 11 '16 at 05:33
  • @patrick, your username and password would be required if you push to a repository you are a collaborator of. Imagine what could happen otherwise: I clone your repo with https, then start pushing random stuff just by entering my username and password. The only way I should be able to push stuff into your repo, is for you to tell github that it's ok, I'm cool. – Shahbaz Jun 11 '16 at 16:07
  • 1
    "if you are not authorized to push, you need to ask the author to give you permission." HOW TO ASK, MESSAGE, MAIL or WHAT? – Anurag Awasthi Mar 19 '17 at 10:41
  • @AnuragAwasthi, message mail or whatever way you can reach them. – Shahbaz Mar 19 '17 at 16:38
  • After an hour of trying the above answers and deleting ALL of my credentials this turned out to be the problem. – Ju66ernaut Aug 09 '18 at 21:15
2

Another way to get this error, is if you have duplicate or conflicting ~/.ssh/* entries. First check what is on your ssh key-chain with:

$ ssh-add -l
2048 SHA256:<hash1> email2@gmail.com (RSA)
2048 SHA256:<hash2> email1@gmail.com (RSA)
2048 SHA256:<hash3> email1@gmail.com (RSA)

As you can see there are two emails which are the same, and easy for you to get confused. Then check your config file:

$ cat ~/.ssh/config

# GitHub: email1@gmail.com
Host github_ex
 HostName github.com
 PreferredAuthentications publickey
 IdentityFile ~/.ssh/github_ex

# GitHub: email2@gmail.com
Host github
 HostName github.com
 PreferredAuthentications publickey
 IdentityFile ~/.ssh/github

# Bitbucket: email1@gmail.com
Host bitbucket
 HostName bitbucket.org
 PreferredAuthentications publickey
 IdentityFile ~/.ssh/bitbuc

Here you see that you have two different email accounts to github but same HostName. Someone is bound to get confused, including your git.

To resolve, manually remove (after copying) the (default) files:

cd ~/.ssh
rm id_rsa
rm id_rsa.pub

Now copy back the one you want to use, for example Host github:

cp -a github id_rsa
cp -a github.pub id_rsa.pub

Then try again.

For some reason, removing keys with ssh-add -d id_rsa didn't work as expected, as it seem that key-chain is cached.

not2qubit
  • 14,531
  • 8
  • 95
  • 135
2

I had this problem too but managed to solve it, the error is that ur computer has saved a git username and password so if you shift to another account the error 403 will appear. 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.

1

Based on the information that the original poster has provided so far, it might be the case that the project owners of EasySoftwareLicensing/software-licensing-php will only accept pull requests from forks, so you may need to fork the main repo and push to your fork, then make pull requests from it to the main repo.

See the following GitHub help articles for instructions:

  1. Fork a Repo.
  2. Collaborating.
0

one final answer (the others no doubt really answered it): it may also be, you are running a really old git version. upgrade to a newer git that gives you the proper options (use of PAT, authenticate via browser, etc.).

0

Now you may benefit from using 'fine grained tokens'

Available here if you're logged into github: https://github.com/settings/tokens

Set up your token then either clone the repo using git clone https://username:github_pat_token@github.com/ExampleOwner/example-repo.git

or just set the remote url if already cloned git remote set-url origin https://username:github_pat_token@github.com/ExampleOwner/example-repo.git

Tristanisginger
  • 2,181
  • 4
  • 28
  • 41