-1

Why am I getting permission denied error while pushing code to remote in git ?

My global config user is ninadraj221 however I have added one local config user as ninadraj321. Now I'm trying to push to ninadraj321's repo from the same ninadraj321 local config but I am getting error as

$ git push -u origin master
remote: Permission to ninadraj321/TestRepo.git denied to ninadraj221.
fatal: unable to access 'https://github.com/ninadraj321/TestRepo.git/': The requested URL returned error: 403

Why is it not overriding my global user while pushing to remote ? However while committing I can clearly see the author as ninadraj321 ? Am I missing something over here ?

j6t
  • 9,150
  • 1
  • 15
  • 35

1 Answers1

0

Probably because what you've set is user.name and not credential.username.

The Git FAQ explains what user.name does, and it controls the name, which is traditionally a personal name (that is, a form of the name other humans call you), that's embedded in commits. It goes on to state the following:

This configuration doesn’t have any effect on authenticating to remote services; for that, see credential.username.

The FAQ also recommends how to deal with multiple accounts over HTTP:

Usually the easiest way to distinguish between these accounts is to use the username in the URL. For example, if you have the accounts author and committer on git.example.org, you can use the URLs https://author@git.example.org/org1/project1.git and https://committer@git.example.org/org2/project2.git. This way, when you use a credential helper, it will automatically try to look up the correct credentials for your account. If you already have a remote set up, you can change the URL with something like git remote set-url origin https://author@git.example.org/org1/project1.git (see git-remote(1) for details).

You could also set credential.username in your local repository, but note that if you have multiple remotes, that will apply to all of them.

bk2204
  • 64,793
  • 6
  • 84
  • 100