简体   繁体   English

设置git推送到另一个用户的Github仓库?

[英]Set up git to push to another user's Github repo?

Let's say I'm user1 and I have a Github account at http://github.com/user1 . 假设我是user1 ,我在http://github.com/user1有一个Github帐户。 Naturally, I'd set up git locally as so: 当然,我会在本地设置git:

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

What would I do if I have fetch & push permissions to someone else's repo (let's say user2 ) whose repo is located at http://github.com/user2/user2srepo.git ? 如果我对其他人的仓库(比如说user2 )提取和推送权限,我的回复是在http://github.com/user2/user2srepo.git怎么办?

EDIT: Sorry, everyone is right with their answers. 编辑:对不起,每个人都对他们的答案是正确的。 I should have clarified that I used to have it set up as origin http://github.com/user2/user2srepo.git but I wanted to avoid being asked for user credentials every single time I pushed. 我应该澄清一下,我曾经将它设置为origin http://github.com/user2/user2srepo.git但我想避免每次推送时都被要求提供用户凭据。

Assuming your github repos are both for the same codebase, you can add them both as remotes to your local repo: 假设你的github repos都是相同的代码库,你可以将它们作为遥控器添加到你的本地仓库:

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

Then use that alias whenever you need it: 然后在需要时使用该别名:

git fetch otherusersorigin
git push otherusersorigin

To do this with no authentication prompt, set up SSH keys for your self according the standard GitHub instructions and get the other person to add you as a collaborator on that repo. 要在没有身份验证提示的情况下执行此操作,请根据标准GitHub说明为您自己设置SSH密钥,并让其他人将您添加为该repo上的协作者。

Turns out it's easier than I thought. 事实证明它比我想象的要容易。 Thanks to the help of @MattGibson and @eykanal in the comments, I realized that I could just set the remote as follows: 感谢@MattGibson和@eykanal在评论中的帮助,我意识到我可以按如下方式设置遥控器:

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

The difference here being that the user is setup as user2 and not my own username. 这里的区别在于用户被设置为user2而不是我自己的用户名。 I mistakenly thought I'd need to enter user2 's credentials, but that's not the case if I've been set as a collaborator on user2srepo . 我错误地认为我需要输入user2的凭据,但如果我已经被设置为user2srepo的协作者, user2srepo

For those interested, the command to set this if you already have the remote set is as follows: 对于那些感兴趣的人,如果您已经拥有远程集,则设置此命令的命令如下:

git remote set-url origin git@github.com:user2/user2srepo.git

If you have write permissions to that repo, simply clone that repository and commit directly to it. 如果您对该repo具有写权限,只需克隆该存储库并直接提交给它。 You don't need to go through the forking process. 您不需要经历分叉过程。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM