2016-08-18 42 views
1

我旅行,没有我的普通笔记本电脑。我需要创建一个新项目,并将其作为新的回购站点推送到我的GitHub。我的朋友,谁拥有这台笔记本电脑(我正在写这个问题)也在GitHub上做了很多东西。所以我在本地创建了项目,然后登录到GitHub并创建了远程回购。 GitHub的要我运行下面的命令,典型为所有新回购:权限被拒绝给我自己的GitHub回购

git init 
git add README.md 
git commit -m "first commit" 
git remote add origin https://github.com/mygithubuser/example-app.git 
git push -u origin master 

当我就去做git push -u origin master,我收到以下错误:

remote: Permission to mygithubuser/example-app.git denied to other-user. 
fatal: unable to access 'https://github.com/mygithubuser/example-app.git/': The requested URL returned error: 403 

...其中other-user是我的朋友的GitHub用户名(毕竟,我正在使用他的笔记本电脑)。所以,我抬头典型的修复,并试图运行:

git remote set-url origin https://github.com/mygithubuser/example-app.git 

的Git没有抱怨,所以后来我试图重新运行:

git push -u origin master 

...但我得到相同的“403”错误。任何想法,我要走错了,这里的修复是什么?理想情况下,有一些魔术命令会要求我以我的典型用户身份进行身份验证?

+1

能临时添加ssh酒馆关键看你在github上键,然后将其删除,当你给一台笔记本电脑回来吗?听起来像是我最简单的选择。 – speedingdeer

+0

谢谢@speedingeer(+1) - 这将如何工作?我在哪里可以找到正在使用的SSH发布密钥? '〜/ .ssh/known_hosts'不包含任何GitHub引用...... – smeeb

+2

github具有优秀的使用ssh密钥的文档。 https://help.github.com/articles/generating-an-ssh-key/ – speedingdeer

回答

1

您配置谁有权访问设置你的回购/合作者,您需要登录自己一样:https://github.com/mygithubuser/example-app/settings/collaboration

如果你想提交笔者为比被提交,你可以使用--author用户不同:

git commit --author="John Doe <[email protected]>" 

该示例来自excellent git tutorial from Tower

与此修订者将是:other-user和作者会在你指定的人。确保您使用的是正确的用户名称/电子邮件。

+0

Thanks @Felipe Cypriano(+1) - 如果我的典型Github用户是'mygithubuser',并且我遵循上面的建议,那么推送会显示'mygithubuser'推动了更改,或者'other-suer'推动了更改?我需要它来自我('mygithubuser')! – smeeb

+0

我的建议可以访问'other-user',所以如果你和他一起推,它会显示为他。所以如果你不想提供'other-user'提交权限,不要按照我所说的去做。 –

+0

@smeeb我增加了一些关于如何使用'other-user'来提交提交信息的更多信息,但是把自己作为作者。 –

0

只要给你的朋友推送你的仓库的权利。
作者和提交者仍然是你。
实际推送的人并不重要。
谁推送不会以任何方式修改提交元数据。

0

打开终端,运行

git credential-osxkeychain erase 
host=github.com 
protocol=https 
[press return] 

后,push -u origin master