如何将更改作为其他用户推送到github存储库?

时间:2015-06-07 23:35:03

标签: git github

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

我在本地克隆了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)使用我在上面配置并用于克隆回购的用户名(“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

2 个答案:

答案 0 :(得分:0)

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

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

所以你使用 https 协议克隆了这个,你显然已经使用 reedndbn https 建立了一个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

答案 1 :(得分:0)

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

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

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