我和一个朋友共用我的电脑。我已经在Windows 7上使用git bash shell推送到GitHub。现在我们在那台电脑上做一个不同的项目,我需要她推到她的账户上。但它一直试图使用我的用户名,并说我没有访问她的存储库:

$ git push her_github_repository our_branch
ERROR: Permission to her_username/repository.git denied to my_username.
fatal: The remote end hung up unexpectedly

重要:2021年8月13日删除了对密码验证的支持。


当前回答

修改项目根目录下的。git目录中的config文件:[PROJECT_PATH]/.git/config

我在这个文件的末尾添加了以下部分。之后我就可以用我的新名字按遥控器了。

[user]
    name = Your Name
    email = MyEmailAddress@company.com

其他回答

转到凭证管理器 转到Windows凭证 删除通用凭证下的条目 再次尝试连接。

我一直在使用一台机器,用不同的用户名将代码推送到两个不同的GitHub帐户。假设您已经设置了一个帐户,并想添加一个新帐户:

生成新的SSH密钥SSH -keygen -t rsa -C "myaddress@example.com" 保存它,但记住不要覆盖现有的id_rsa。给它一个不同的名字,例如id_rsa_another 复制密钥的内容到你的GitHub帐户:

设置-> SSH和GPG密钥-> SSH新密钥->标签粘贴 the key ->添加SSH密钥

将密钥添加到ssh代理:ssh- Add ~/.ssh/id_rsa_another 安装一个GitHub主机:用touch ~/创建一个配置文件。Ssh /config并编辑文件,为您的帐户提供配置:

#first account
Host github.com-first
    HostName github.com
    User git
    IdentityFile ~/.ssh/id_rsa

#another account
Host github.com-another
    HostName github.com
    User git
    IdentityFile ~/.ssh/id_rsa_another

现在您应该能够根据您添加到ssh代理的键从不同的帐户推送,即使用您的第一个帐户 ssh-add ~ / . ssh / id_rsa。

你可能还想更改你的用户邮箱:

Git配置——全局用户。电子邮件“myaddress@example.com”

或者在向其中一个帐户发送代码时,在权限错误的情况下清除SSH密钥:

ssh-add - d

git config user.name只改变我提交的名称。我还是推不动。这就是我解决它的方法,我认为对我来说是一个简单的方法。

在要使用的计算机上使用的用户名下生成一个SSH密钥 https://help.github.com/articles/connecting-to-github-with-ssh/ 将此键添加到要推送的github用户帐户 https://help.github.com/articles/adding-a-new-ssh-key-to-your-github-account/ 选择SSH克隆

你可以以这个用户推入到那个回购。

我使用自定义的IdentityFile设置了一个ssh别名,并重写了起源,以使用我的自定义me-github主机名。

#when prompted enter `id_rsa_user1` as filename
ssh-keygen -t rsa

# ~/.ssh/config
Host user1-github
HostName github.com
Port 22
User git
IdentityFile ~/.ssh/id_rsa_user1

#check original remote origin url
git remote -v
origin git@github.com:user1/my-repo.git

#change it to use your custom `user1-github` hostname
git remote rm origin
git remote add origin git@user1-github:user1/my-repo.git

如果这是你的问题

remote: Permission to username1/repo.git denied to username2.
fatal: unable to access 'https://github.com/username1/repo.git/':
The requested URL returned error: 403

除了使用git配置从终端更改用户名和电子邮件:

$ git config --global user.name "Bob"
$ git config --global user.email "bob@example.com"

您需要从钥匙串中删除授权信息。我花了好几个小时才想出这个解决办法。我发现我的钥匙链里也有证书。

打开钥匙链访问,点击所有项目,搜索git。删除所有keychain