1

I'm trying to create a pull request on GitHub for project "original/QWERTY" so I forked the repo to "Mark/QWERTY". In Eclipse, I already have a repository set up for "original/QWERTY" and that project is in my workspace, named QWERTY.

Now if I create a new repository pointing at "Mark/QWERTY", I'll have two projects with the same name and both Eclipse and me won't like it.

I thought that it should be possible to have a branch or another remote under a repository and switch between them instead of having two copies (I mean just store the diffs). The problem is that they are different projects on GitHub so I'm not sure how to do it.

What is the correct way to set up two GitHub projects to create a pull request from my fork to the original one in Eclipse with EGit?

Rüdiger Herrmann
  • 20,512
  • 11
  • 62
  • 79
Mark
  • 2,167
  • 4
  • 32
  • 64

2 Answers2

3

The usual workflow for forked repositories is to have a single local repository with a single work directory that is configured to fetch and push from/to multiple remote repositories.

With this setup, you can switch between branches that originate from different remote repositories.

The Fork a repo documentation of GitHub explains this setup when using CLI Git. Most of it should also apply to repositories hosted elsewhere.

Using the EGit documentation, it should be possible to translate these instructions into the corresponding actions in EGit.

How to manage multiple remotes with EGit is documented here: https://wiki.eclipse.org/EGit/User_Guide#Remote_Repositories

Rüdiger Herrmann
  • 20,512
  • 11
  • 62
  • 79
  • Thanks for the helpful overview and links, it helped a lot. I submitted my own answer which is more detailed and suitable for new users like myself. If you can look at it that it's correct it will be very useful. – Mark Oct 29 '18 at 14:40
1

Using the information from Rudiger's comment and answer and my trial and error with branches I made my own steps. This picture also helps with terminology.

First, do these 2 things in any order:

  • fork the original project in the github website so now you have the original and the fork. They have the same code and branches.
  • create a local repository pointing to the original repo on github. Let's say you decided to select only the master branch.
    • Remotes: you get a new remote I'll call origin (default). configure its fetch if it's not done for you, the default specification is +refs/heads/*:refs/remotes/origin/*. This ref spec maps all the repo branches to Remote Tracking branches with the same name. If you want to only fetch the master branch then use +refs/heads/master:refs/remotes/origin/master.
    • Branches: you get a "Remote Tracking" branch called origin/master and a local branch called master with configuration of "Remote: origin" and "Upstream Branch: refs/heads/master". You will be working under the local master as it's the only branch right now.

Now you want to be able to push to your fork so you can create PR. You can and already did pull from the original to keep getting updates from other people's work.

  • Right click on "Remotes" and create a new remote, I'll call it fork (call it whatever you need). Configure its push.
    • the URI points to your fork the same way the origin Remote URI points to the original.
    • The ref mapping maps the branches. Go to "Advanced" and click "Add All Branch Specs" if it isn't done for you. You should get the spec refs/heads/*:refs/heads/*. It's easy to work with this spec but you can change it to whatever you need.
  • Create a local branch (right click -> switch to -> new branch) whose source is the local branch named master and the branch name is whatever suits what it does. it can be the master branch or a new branch that let's say fixes a bug, so bug 123. You do not have a Remote Tracking branch because those are used for pulls. If you also pull from fork then you will need to configure that in the Remote fork and get a remote branch.
  • Now you are working on a local branch bug 123 (you can see a checkmark next to it). Fix the bug in your code and in the Git Staging view you should see the files changed and the title is <Repository name> [bug 123]. Make sure you are going to commit/push to the correct branch! Stage whatever you need and commit (adds the changes to the local branch bug123) and push (creates a branch on the github repo called bug 123 if you stayed with the default spec).
  • Now go to the GitHub repo page of either the original or the fork and the UI will tell you that you can create a PR. From there GitHub will guide you.

Once the PR is merged into the master branch of the original on GitHubm, you will want to fetch from the master.

  • Right click on the Remote origin or its fetch "subdir" and choose fetch. The will fetch any changes in all the remote branches because the fetch spec we used maps all the branches (we used the * character).

That's it. Continue to switch to a local branch which maps to your fork based on the updated master, fix bug, commit and push, create PR, wait for merge into the original, fetch and pull from the original.

Mark
  • 2,167
  • 4
  • 32
  • 64