Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pull request from a different repository

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?

like image 375
omer mazig Avatar asked Aug 12 '16 13:08

omer mazig


People also ask

Can I make a pull request to my own repository?

Once you've committed changes to your local copy of the repository, click the Create Pull Request icon. Check that the local branch and repository you're merging from, and the remote branch and repository you're merging into, are correct. Then give the pull request a title and a description. Click Create.

Is forking the same as branching?

Forking creates a full copy of your repository, whereas branching only adds a branch to your exiting tree. The file size of branch can vary depending on the branch that you are on. Under the hood git readily accesses the different files and commits depending on what branch you are using.

Can you clone a pull request?

The short answer for cloning a pull request is, you can't simply clone a pull request.


2 Answers

  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.
like image 65
Xiong Chiamiov Avatar answered Sep 28 '22 07:09

Xiong Chiamiov


unfortunately there is no way to merge two branches that dont have a common ancestor commit. even if the files are the same.

A very hacky workaround however goes as follows:

  1. fork and clone the original repo
  2. in that repo, checkout to the commit that you initially downloaded.
  3. in your non-forked, downloaded repo, checkout to the first commit you made after having downloaded it.
  4. copy those files into the forked repo
  5. Recreate the commit in the forked repo
  6. repeat steps 3-5, but for each successive commit.
  7. Once completed, you can open up a pull request with you newly created git history

Its a laborious process, and you could probably create a tool to do it, but if its not a lot of commits, or you dont mind combining a few commits into one. (to do this, in step 3, just skip a couple of commits, the code from previous commits will still be there)

like image 32
Marcus Gosselin Avatar answered Sep 28 '22 08:09

Marcus Gosselin