Pull request from a different repository

omer mazig picture omer mazig · Aug 12, 2016 · Viewed 8.8k times · Source

I didn't know how forks and clones work. So in order to copy someone else's repo and work on it, I downloaded the repo's files (using no source control), created my own new repository, and then committed those files to it.

I want to pull request my repo's master to the original repo, but I can't because it's not a fork. Furthermore - git doesn't even know that they originate from the same source, and hence if I checkout the original repo, open a new fork, copy-paste all the files from my private repo to the new fork, and pull request it back in, it will show it as a single giant commit, and I'll lose all of the commit and comment history on the old repo, which will be terrible.

Is there a way for me to pull request my changes back into the original repo without losing all the history of my copied repo?

Answer

Xiong Chiamiov picture Xiong Chiamiov · Aug 12, 2016
  1. Make sure you have a copy of your changes on your local computer (I'll call this "the copied repo") and delete the project on GitHub, if you've created one.
  2. Click "Fork" on the upstream project's GitHub page.
  3. After the forking process is complete, clone that repository to your local computer (I'll call this "the forked repo").
  4. Copy all changed files from the copied repo into the forked repo.
  5. Verify that it's working as you expect, then look at the changes using git status and git diff and commit them.
  6. Push those changes back to GitHub.
  7. In a moment, a banner should appear on the cloned repo's GitHub page that provides a button to open a pull request back to the upstream repo. Click that and open the pull.