【问题标题】:How can I push changes to a github repository as a different user?如何以其他用户身份将更改推送到 github 存储库?
【发布时间】:2015-06-07 23:35:03
【问题描述】:

我在 github 上作为 natereed (nate@natereed.com) 分叉了一个 git repo。

我在本地克隆了 repo 并发出以下命令来配置用于推送更改的身份:

git config user.name "natereed"
git config user.email "nate@natereed.com"

我尝试推送到原点,但得到 403(未经授权):

USAU9900:ExData_Plotting1 reedn$ git push origin master
remote: Permission to natereed/ExData_Plotting1.git denied to reedndnb.
fatal: unable to access 'https://github.com/natereed/ExData_Plotting1/': The requested URL returned error: 403

它似乎仍在使用不同的身份 (reedndbn)。如何强制它(git/ssh)使用我在上面配置并用于克隆 repo 的用户名(“natereed”)?

这是我的 .git/config:

USAU9900:ExData_Plotting1 reedn$ more .git/config 
[core]
        repositoryformatversion = 0
        filemode = true
        bare = false
        logallrefupdates = true
        ignorecase = true
        precomposeunicode = true
[remote "origin"]
        url = https://github.com/natereed/ExData_Plotting1
        fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
        remote = origin
        merge = refs/heads/master
[user]
        name = natereed
        email = nate@natereed.com

【问题讨论】:

    标签: git github


    【解决方案1】:

    首先在 git 中添加 SHH 密钥并为您的系统创建权限

    <Use default path> $ ssh-keygen -t rsa -C <email id>

    $ cat ~/.ssh/id_rsa.pub 在 git add shh 中粘贴密钥。 然后 'git config --global user.name 'USER_NAME' ‘git config --global user.email “EMAIL_ID” etc..

    【讨论】:

      【解决方案2】:

      在你的 .git/config 你有这个:

      [remote "origin"]
          url = https://github.com/natereed/ExData_Plotting1
          fetch = +refs/heads/*:refs/remotes/origin/*
      

      因此,您使用 https 协议克隆了它,并且您显然已经使用 reedndbnhttps 设置了 github 关联。当我通过 https 连接到 github 时,系统会提示我输入用户名和密码。

      所以将url = https://github.com/natereed/ExData_Plotting1 更改为 https://natereed@github.com/natreeed/ExData_Plotting1.git。或者,如果您为 natereed 设置了 github ssh 密钥关联,则可以使用 git@github.com:natereed/ExData_Plotting1.git

      或者(我想有些人会说更好的方法)是使用 git remote set-url 命令更改它。见Changing a remote's URL

      【讨论】:

      • 我不想以 reedndnb 的身份提交更改。拥有 repo 的帐户是用户“natereed”。奇怪的是,这也是我的 .git/config 中的帐户。这应该有效,但没有......
      • 感谢您添加完整的配置。在远程源下,您使用的是 https,而不是 ssh。因此,将其更改为: git@github.com:natereed/ExData_Plotting1.git On github.com/natereed/ExData_Plotting1 在“克隆”部分下是您获取 ssh url 的地方。
      • 你能解释一下为什么使用 ssh 而不是 https 作为远程源吗?它确实使错误消失,但我不明白为什么。
      猜你喜欢
      • 2011-06-07
      • 2022-01-17
      • 1970-01-01
      • 2016-03-20
      • 2012-08-25
      • 1970-01-01
      • 2021-10-21
      • 2018-04-11
      • 1970-01-01
      相关资源
      最近更新 更多