简体   繁体   中英

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 . Naturally, I'd set up git locally as so:

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 ?

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.

Assuming your github repos are both for the same codebase, you can add them both as remotes to your local repo:

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.

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:

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. 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 .

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. You don't need to go through the forking process.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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