我和一个朋友共用我的电脑。我已经在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日删除了对密码验证的支持。


当前回答

您可以使用不同的帐号进行推送。 例如,如果您的帐户是存储在.gitconfig中的帐户A,您想使用帐户B,它是您想要推送的回购的所有者。

账号B: B_user_name, B_password SSH链接示例:https://github.com/B_user_name/project.git

B账号推送为:

$ git push https://'B_user_name':'B_password'@github.com/B_user_name/project.git

查看.gitconfig中的帐户

$git配置——global——list $git配置——global -e(也可以更改帐户)

其他回答

发生提交的用户id存储在配置文件中。

转到存储库的顶部 vi . /配置

更改“[remote "origin"]后列出的url行,使其具有适当的用户id

请遵循以下步骤:

你必须明白这一点,在提交之前定义作者! 提交已经被冻结:它们拥有为其作者和提交者设置的任何名称,并且这些名称不能更改。

# you can check what's currently:
git config user.name
git config user.email

git config user.name "your_github_username"
git config user.email "your_github_email"

# Again check what's currently:
git config user.name
git config user.email

检查你的提交被标记到谁?

git log
# once you're confirmed that it's tagged to you, then you should move to step 3

如果作者是错误的,那么您可以轻松地撤消上次提交而不会丢失更改

此外,在移动到步骤3之前,不要忘记遵循步骤1进行完整性检查。

提示自己输入github_username和github_password

git config --local credential.helper ""
git push
# it will ask you to enter your github_username and github_password

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

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

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

在git bash shell中,导航到你朋友的存储库并键入以下内容:

git config --local credential.username "friend's_username"

现在,凭据存储将使用属于她的用户名而不是您的用户名的凭据。

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克隆

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