Search code examples
githubgit-push

How to push changes from a forked project to the original project?


I’m supposed to work on my client's project on GitHub, where the changes would be on his repository. I tried to follow the fork example, but could only get the changes to go to my account repository?

In the example on GitHub, to fork a repo, they create a remote called upstream to point to the original project. I can get the changes from it by

get fetch upstream
git merge upstream/master

I was able to upload the changes into my repo by

git push –u  origin

which copied my changes to my account.

I tried

git push –u upstream

To push my changes on the original account. I got the following error

You can’t push to git://github.com.octocat/SpoonKnife.git use git@github.comoctocat/Spoon0-Knife.git


Solution

  • Basically, in order to collaborate with your client, you've got two main options:

    • Send your client a pull request (more info on this in this GitHub help item). This allows your client to review, discuss and/or request some changes to your proposal before merging it.
    • Request from your client to be added as a committer to their project. This would allow you to directly push your commits to their repository, without the need for a fork/cloned repository on your side.

    As a side note, Spoon-Knife.git is one of GitHub's read-only repository (used for demonstration purpose) and you will not be able to commit to that (unless your client is GitHub). Thus, your client's upstream git remote should point to a different repository

    Here are the steps (to be followed after you forked and cloned the repository to your local disk):

    1. Remove the upstream reference: git remote rm upstream
    2. Add in your client's info - git remote add upstream git@xxxxxx
    3. Push your changes - git push -u upstream master . git push -u will set the HEAD of the remote repository.
    4. Same if you want to pull - git pull upstream master

    If you prefer the name origin replace upstream with origin, but still follow step 1 to remove the reference to Spoon-Knife.git. Then in step 2 - git remote add origin git@xxxx.