6

假设我user1和我有一个 Github 帐户http://github.com/user1。自然,我会在本地设置 git,如下所示:

origin git@github.com:user1/repo.git (fetch)
origin git@github.com:user1/repo.git (push)

如果我有获取和推送权限到其他人的仓库(比方说user2),其仓库位于 ,我会怎么做http://github.com/user2/user2srepo.git

编辑:对不起,每个人的答案都是正确的。我应该澄清一下,我曾经将其设置为,origin http://github.com/user2/user2srepo.git但我想避免每次推送时都被要求提供用户凭据。

4

3 回答 3

8

假设您的 github 存储库都用于相同的代码库,您可以将它们都作为遥控器添加到本地存储库:

git remote add otherusersorigin http://github.com/user2/user2srepo.git

然后在需要时使用该别名:

git fetch otherusersorigin
git push otherusersorigin

要在没有身份验证提示的情况下执行此操作,请根据标准 GitHub 说明为您自己设置 SSH 密钥,并让其他人将您添加为该存储库的协作者。

于 2012-07-17T16:21:20.347 回答
4

事实证明这比我想象的要容易。感谢@MattGibson 和@eykanal 在评论中的帮助,我意识到我可以按如下方式设置遥控器:

origin git@github.com:user2/user2srepo.git (fetch)
origin git@github.com:user2/user2srepo.git (push)

这里的区别是用户被设置为user2而不是我自己的用户名。我错误地认为我需要输入user2的凭据,但如果我被设置为user2srepo.

对于那些感兴趣的人,如果您已经拥有远程设置,则设置此命令的命令如下:

git remote set-url origin git@github.com:user2/user2srepo.git
于 2012-07-17T16:32:06.597 回答
1

如果您对该存储库具有写入权限,只需克隆该存储库并直接提交到它。你不需要经历分叉过程。

于 2012-07-17T16:21:33.527 回答