git - git push 错误:权限拒绝
问题描述
一个月前,我在我的mac上配置了两个github账号:一个是工作账号,一个是个人账号。我已经用了一个月没有问题。在一天中提交/推送/等以回购工作。晚上,在几个个人回购中提交/推送/等。突然,今天我无法在我的一个个人帐户中推送一些更改,错误是:
git push --set-upstream origin <branch>
ERROR: Permission to <repo>.git denied to <work-account>.
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
我不知道为什么 git push 命令试图使用我的工作帐户进行推送!?!?!?
我之前的更改和推送是在 7 天前使用我的个人帐户(没有问题)。我没有更改配置中的任何内容(ssh、.git/config 文件等)!
我在 repo 的目录中尝试了这个:
git config user.email
git config user.name
电子邮件是我的个人电子邮件,所以这是正确的。
为什么 git 使用我的工作帐户?即使git config
命令显示我的个人帐户?此外,这是几天前工作的......
笔记2:
- 我在 ~/.ssh 目录中定义了两个帐户:id_rsa、id_rsa.pub、id_rsa_、id_rsa_.pub。
- ~/.ssh/config 也被定义:
Host github.com
Hostname github.com
User git
AddKeysToAgent yes
UseKeychain yes
IdentityFile ~/.ssh/id_rsa
Host <githubpersonal>
Hostname github.com
User git
IdentityFile ~/.ssh/id_rsa_<personal_account>
- 回购的远程来源我认为它定义明确:
[remote "origin"]
url = git@<githubpersonal>:<personal_account>/<repo>.git
fetch = +refs/heads/*:refs/remotes/origin/*
- 如果我跑步,
git remote -v
我会得到:
origin git@<githubpersonal>:<personal_account>/<repo>.git (fetch)
origin git@<githubpersonal>:<personal_account>/<repo>.git (push)
我不知道为什么不再工作了......
解决方案
检查您的配置文件是否有任何 pushURL 配置,以检查它是否尝试使用您不期望的 URL 进行推送。
注意:您可以测试的 SSH URL 是githubpersonal
,不是git@githubpersonal
,因为 git 已经在~/.ssh/config
ssh -Tv githubpersonal
推荐阅读
- apache - 使用apache mod_wsgi测试报错---windows环境
- python - 绘制 X 轴边距
- javascript - 有没有办法从 ejs 获取内容到 node-js 服务器?
- authentication - Not able to access WSO2 IoTS Device Management Console in wso2-iot-3.3.0 when logged in 'admin'
- php - Commas not found in file with php
- python - 为什么 Python 包在 IDLE 3.7 中运行而不在 Atom 中运行?
- java - 服务器在套接字中关闭后,我可以与同一个客户端建立自动先前连接吗
- rxjs - AngularFire2 承诺进入 Observable 类型问题
- ios - UITableView 中点击的单元格从数组中的最后一个单元格返回标签文本,而不是所选的单元格
- html - 如何使用 Angular 6 获取打字稿文件中多个复选框的值?