Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

git

github

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 [email protected]:user1/repo.git (fetch)
origin [email protected]: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.

like image 685
Nick Avatar asked Jul 17 '12 16:07

Nick


People also ask

How do I push a git code to another account?

As we know we can push code on Github repository with HTTP or SSH. I prefer SSH because we need to configure an account only once. Yes, If you are right we want to push on different account means we need to generate SSH key for every account. Step 2: Now It time to attach the key with your second Github account.

How do I give git permission to push?

Click the "Collaborators" tab. Start typing the collaborator's username. Select the user from the drop-down menu. Click Add.

How do you push to a repo as a collaborator?

The Owner needs to give the Collaborator access. On GitHub, click the settings button on the right, then select Collaborators, and enter your partner's username. To accept access to the Owner's repo, the Collaborator needs to go to https://github.com/notifications. Once there she can accept access to the Owner's repo.

Can anyone push to a public GitHub repo?

Nobody can push directly to your repository if you are not already granting them write access. The process for contributing to a public repository in GitHub starts by forking the repository, then pushing the change onto the forked, then creating a pull request onto the original repository.


2 Answers

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.

like image 79
Matt Gibson Avatar answered Oct 06 '22 00:10

Matt Gibson


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 [email protected]:user2/user2srepo.git (fetch)
origin [email protected]: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 [email protected]:user2/user2srepo.git
like image 30
Nick Avatar answered Oct 05 '22 22:10

Nick