【问题标题】:Commit to master in terminal doesn't recognize my active username提交到终端中的 master 无法识别我的活动用户名
【发布时间】:2018-10-16 21:53:48
【问题描述】:

我正在尝试对我的组织存储库进行初始提交。 当我输入命令时:

$git push -u origin master

返回此错误信息:

远程:(my-work-username)/Team-Website.git 的权限被拒绝(my-personal-username)。 致命:无法访问'https://github.com/(my-work-username)/Team-Website.git/':请求的URL返回错误:403

我已使用以下方式更改了我的用户名和电子邮件:

$git config --global user.name "my-work-username"
$git config --global user.email "my-work-email"

并使用以下方法对其进行了验证:

$git config --list

返回:

user.name=(我的工作用户名) user.email=(我的工作邮箱)

所以我想将我的目录推送到存储库,尽管发生了 403 错误,阻止了这种情况,因为它无法将我当前的用户名识别为与该存储库的授权用户名匹配。

我应该如何让 github 识别授权用户名和活动用户名匹配?

【问题讨论】:

  • git config 仅影响本地内容,例如新提交中包含的信息。身份验证是通过 SSH 密钥或(在您的情况下,因为您使用 HTTPS)应该提示您输入的用户和密码完成的。您是否使用两因素身份验证?因为如果你是,你就不能使用你的常规 GitHub 密码。

标签: git github


【解决方案1】:

来自git config 的配置会影响您的本地设置,例如提交时显示的姓名和电子邮件。它们不会影响用于 github 的用户名。

检查您的origin 的网址: git remote -v

您可能会看到类似origin https://github.com/GithubUsername/GithubRepoName.git (push) 的内容。然后,您可以将用于 HTTPS 身份验证的 Github 用户名添加到 url,方法是更改​​它,如下所示:

git remote set-url origin https://github_user@github.com/Githubusername/GithubReponame.git

然后,当您推送或获取时,系​​统会提示您输入密码。

这假设您使用的是 HTTPS 身份验证并且没有启用 2FA。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-07-14
    • 2015-10-01
    • 1970-01-01
    • 2018-09-23
    • 2022-06-30
    • 2022-11-29
    • 1970-01-01
    相关资源
    最近更新 更多