Eclipse Egit: Update a github fork to merge changes of master repo? - eclipse

I have forked a github repo. Now my worked repo is out of sync with the original repo.
I understand that I need to do a merge, but how to do this with Eclipse git is a bit unclear to me.
Question: How do I update my fork to include changes made to the original repo made by the owner?
Edit 1: I've added another remote. But I don't see any Pull buttons on the context menu:

You do the merge on your local machine and then push the result from your local machine to your own github repo. There is no way to update your github repo directly on the server.
To do that, add that original github repo as a new remote. This is described in the egit user manual. Choose "configure for fetch" instead and give it the URI of the original repo. Afterwards you can simply use the context menu "Pull" on that new remote node to fetch and merge all the new stuff. After finishing the merge, you "Push to upstream", which is your own github repo.

Try the second url under upstream to push your changes. The first one ist just for fetching (see the green/red arrows ;-)

Related

How to work on a project fork when having the original in Eclipse?

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?
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
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.

Update all branches on forked repo with github.com?

I have a forked repo. The original repo has been updated and I need to pull in these changes. I would prefere to use github.com for this rather than the command line if possible.
From the github.com page of my fork I have a button called Compare which allows me to compare my branches with the branches in the original repo, and merge if there are changes. This should do what I want except that the changes I need to update are in a new branch that isn't in my repo.
IMHO, the best way to do this is by installing the Pull app in GitHub.
After forking a repository, you can then enable the app for the
repository, and then configure the app for the forked repository. 🙂

Correct process to merge fork changes into GitHub

I am new to GitHub. I don't know the correct process to merge my changes with the upstream. I followed following steps using EGit (I like to use it because I find it simple). Please help me.
On GitHub I created a fork.
For my fork I cloned a repository in Eclipse and imported respective projects.
In remotes, I added one more for the main project say Upstream(from where I forked) on GitHub.
I added some changes into my local repository.
How can I do the following part? -
Now in the meantime other people added some changes to the upstream. Now I want to integrate my changes(in the fork I created) to the latest changes(upstream) using EGit and push it to my repository and send a pull request.
Please help me.
create another remote corresponding to your fork in Eclipse
publish (push) your changes into your fork repo on github
create a merge request from the web interface in the original github repo, pointing to your changes on github
There is the procedure, how I do it.
GitHub browser UI
delete your fork with too much mess, if exists - this is in your Settings -> Danger Zone, the button is in upper menu bar in the root of fork
fork for you a new one on the foreign page, where I have access
open newly created fork and copy URI to the clipboard
Git perspective in Eclipse
create clone of your fork in my GUI Eclipse
Create a new branch in local branches and activate it
Import project from working tree in Eclipse as general project from Git perspective to actual workspace
do changes, integrate your important files to the general project (add to index etc.)
commit, push
GitHub browser UI
create Pull request from your fork directly from actual branch (recommended) or after merge in master branch
Notice, that in the picture is merge branch selected. In our real case is better to use the name, which is more descriptive.

Egit can't fetch README changes

I'm using Eclipse 4.2.1 and EGIT. I've done the following:
Created an account on Github.
Created a Repo and initialized it with a readMe from Github at the time I created it.
Cloned the repo using EGIT.
Created a Java project in Eclipse, a single class with a main method.
Share the project with GIT. Team-> Share Project-> GIT
In the Configure GIT repo dialog: Selected the repo I just cloned from Github.
Do a commit.
Push to remote origin.
Go back to Github and make a change to the readMe. (This shows in the commits on Github)
Fetch the changes with EGIT.
The changed readMe is shown in the remote tracking branch in EGIT but not in my local master branch. I tried refreshing but it still doesn't work. After doing this my local master is one behind and I can't push. I get rejected non-fast forward.
I can fix this by creating a new local branch based on HEAD then merging it into my local master. But why is this happening? Is anyone else experiencing this?
Fetching only gets the changes from github into the remote tracking branch (imagine this as a kind of index) on your local machine, but not into your working directory (the real files you edit). You still have to merge the remote changes into your local branch (which you can do by expanding the repository node Branches -> Remote Tracking -> origin/master and selecting "Merge" in the context menu).
If you always just want to fetch and immediately merge the remote changes, use the "Pull" command instead of the "Fetch" command, it is a combination of fetch and merge.

Why does nothing happen when I click fork on github?

I created a repository in github and then issued the following command on my local box:
git push origin master
Now I see all of the files on github.
I would like to start work on making changes. With this in mind I clicked the fork button on the
github screen. However nothing happens. I see a message at the bottom of my browser screen but
that's all.
How do I copy my "forked" version to my local computer?
If you want to work on your GitHub repo, you need to clone it locally.
If you want others to contribute directly in your repo, you need to declare them as collaborator.
You could set up a dedicated branch for them to use.
If you don't want them to push directly to your repo, then your colleagues need to fork your repo, and clone their fork locally.
If it's your repository, there's no need to fork the repo.
If I read your question correctly, to make changes, simply edit the files in question in a text editor, save them, open terminal, change directory to the one with the code, and write git add . then git commit -m "Your commit message" and then git push. The new code should be updated in GitHub as a new commit.