Git: How to push to someone's fork?

Viewed 3123

I work for an open-source project and forked it already. Someone has forked it too and has been working with some interesting ideas which won't be pushed to origin soon. I want to help him thus I cloned his fork to my computer. However, I can't push directly my work to his fork. I can't fork him either since I have a fork from origin already. What should I do? Thanks

2 Answers

Suppose your repository looked like this:

enter image description here

#Add the forked repo as another remote to your local repository
git remote add someone https://fork.url                 #create remote called "someone"

#fetch the changes from that remote
git fetch someone

enter image description here

#rebase the work you want to send onto the fork's work
git branch for-someone my-branch                        #create branch "for-someone" at "my-branch"
git rebase master for-someone --onto someone/master     #take commits from the "for-someone" branch down to your "master" branch and rebase it onto someone's "master" branch

enter image description here

#then push your changes to the other remote
git push someone for-someone                            #push branch "for-someone" to the "someone" remote

Insert more appropriate remote and branch names.

You can do the two things as @jeff-mercado mentioned. This will be a complex task and I would advise you to use a GUI based git client for this. I have faced the same problem as you faced and found Sublime Merge to be very useful.

I would suggest asking him to send you a PR. Then you will be able to merge his changes into your repository Finally you can push the merged repo on your github and ask him to clone it and push. (This is assuming the other guy won't do the work of merging your PR, which will be easier for you.)

Related