2

I have two github account--tuomao and maomao1234,my computer global config user.name is tuomao and I add an ssh key to my computer for tuomao. I use maomao1234 to create a repository Hospital.

Then I clone it into my computer. I have change this repository setting with following instruction.

git config user.name maomao1234
git config user.email myemail

Then I edit some file of the repository and commit my changes,here is my commit log

tuomao@TUOMAO-PC /k/桌面资料/code/temp2/Hospital (master)
$ git log
commit 5a35e6dad5caf21c482db9e5e7fd62e01ee2b807
Author: maomao1234 <944925840@qq.com>
Date:   Fri May 6 11:51:55 2016 +0800

from the log,we can see that my commit user is right.

However,when I use git push to push my commit,it happens error

$ git push  https://github.com/maomao1234/Hospital.git
remote: Permission to maomao1234/Hospital.git denied to tuomao.
fatal: unable to access 'https://github.com/maomao1234/Hospital.git/': The          requested URL returned error: 403

form the error log,we can see the push user is not right.Why I have already change the repository user and the commit user is right but the push user is fault?

how can I push my changes with user maomao1234?

  • Do you also have an SSH key for maomao1234? – pll33 May 06 '16 at 04:37
  • no. but even I dont't add an ssh key for maomao1234,console will prompt me to input password? –  May 06 '16 at 04:44
  • When you make git commands, you're still logged in as tuomao attempting to push to the maomao1234 repository where tuomao does not have write access. The git config setting only changes your displayed name and email for a particular repository, it's not used to log you in/out or switch accounts. If you want to push changes with maomao1234, you have to set up another SSH key pair for the other account – pll33 May 06 '16 at 04:52

1 Answers1

1

git push https://... means your ssh keys are completely ignored, since you are using the https protocol.

from the log,we can see that my commit user is right.

This has nothing to do with the account used to push: you can create any commit with any git config user.name and still be able to push (with https or ssh) to a repo, provided you use, at push time, the right account or ssh key.

Check git remote -v to see exactly what remote url is used.

An https one should ask you for a user and password.
An ssh one means you need to make sure %HOME%\.ssh\id_rsa.pub is the key associated to maomao1234 and not tuomao.
If you need to manage multiple ssh keys, see "How to work on personal GitHub repo from office computer whose SSH key is already added to a work related GitHub account?".

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250