首页 > 解决方案 > git command pushes as wrong user

问题描述

I have read through multiple questions addressing this problem, but none of the solutions work for me. I have changed the user.name and user.email of my local repository, yet when pushing it doesn't work. Here is what my terminal looks like:

$ git config --local user.name "myusername"
$ git config --local user.name
myusername
$ git config --local user.email "email@gmail.com"
$ git config --local user.email
myemail@gmail.com
$ git push
remote: Permission to myusername/myusername.github.io.git denied to otheraccount.
fatal: unable to access 'https://github.com/myusername/myusername.github.io.git/': The requested URL returned error: 403

标签: gitgithub

解决方案


看起来您正在使用凭据管理器,并且它为不同的帐户存储了凭据。推送时正在使用这些凭据,而其他帐户无权访问该存储库。

如果您确实有多个帐户并且想同时使用这两个帐户,那么您应该使用Git 常见问题解答中概述的技术( SSH也有一个)。如果您只是拥有不想再使用的凭据,那么您应该使用 Git 常见问题解答中概述的技术来执行此操作。请注意,后一种技术对于 Windows 的 Git Credential Manager 是无效的,您应该查看他们的问题跟踪器以获取解决方法。

您还应该注意,这user.name对身份验证没有任何影响。相反,它是您在提交中放置的名称,并且按照惯例是个人名称(即其他人称呼您的名称)。Git 允许它几乎是任何值,因此允许使用用户名,但不习惯。


推荐阅读