簡體   English   中英

設置git推送到另一個用戶的Github倉庫?

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

假設我是user1 ,我在http://github.com/user1有一個Github帳戶。 當然,我會在本地設置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但我想避免每次推送時都被要求提供用戶憑據。

假設你的github repos都是相同的代碼庫,你可以將它們作為遙控器添加到你的本地倉庫:

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

然后在需要時使用該別名:

git fetch otherusersorigin
git push otherusersorigin

要在沒有身份驗證提示的情況下執行此操作,請根據標准GitHub說明為您自己設置SSH密鑰,並讓其他人將您添加為該repo上的協作者。

事實證明它比我想象的要容易。 感謝@MattGibson和@eykanal在評論中的幫助,我意識到我可以按如下方式設置遙控器:

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

這里的區別在於用戶被設置為user2而不是我自己的用戶名。 我錯誤地認為我需要輸入user2的憑據,但如果我已經被設置為user2srepo的協作者, user2srepo

對於那些感興趣的人,如果您已經擁有遠程集,則設置此命令的命令如下:

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

如果您對該repo具有寫權限,只需克隆該存儲庫並直接提交給它。 您不需要經歷分叉過程。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM