4

I am using Egit with eclipse for working on my java project. I created a branch called branch1 from master and started working on it.

In the mean time my colleague created another branch branch2 from master, made some changes and merged branch2 back to master.

Now I need to get all the changes that were made on master to my branch branch1.

How can I achieve this using eclipse or github and not using any command.

mike
  • 1,233
  • 1
  • 15
  • 36
user9735824
  • 1,196
  • 5
  • 19
  • 36
  • You could either [rebase your branch to the latest master commit](https://wiki.eclipse.org/EGit/User_Guide#Rebasing), merge the changes from master into your branch or cherry pick all commits from master that you want. – howlger Nov 08 '18 at 15:53
  • now I am confused about what to choose between merge and rabase which is new to me. – user9735824 Nov 08 '18 at 15:56
  • Rebasing and merging leads to different histories. It's your choice what you want. If there are none or only few conflicts, I would prefer rebasing: make sure `branch1` is checked-out and in the _History_ view right-click the latest `master` commit (make sure _Show All Branches and Tags_ is enabled, otherwise only `branch1` commits are visible) and choose _Rebase on_. – howlger Nov 08 '18 at 16:03
  • @howlger thanks for your answer. Since I am quite new with git, could you please elaborate steps on answer section. – user9735824 Nov 08 '18 at 16:12
  • Which of the two steps are you stuck on? 1. Make sure `branch1` is checked-out (the project name should be decorated with `[branch1]`; 2. In the _History_ view right-click the latest master commit and choose _Rebase on_. – howlger Nov 08 '18 at 16:19
  • I checked out `branch1`. Now Do i have to do team->rebase on eclipse? i don't see anything on History view. – user9735824 Nov 08 '18 at 16:34
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/183313/discussion-between-user9735824-and-howlger). – user9735824 Nov 08 '18 at 16:37
  • To see also commits of `master` in the _History_ view you have to enable _Show All Branches and Tags_ (the button in the right upper corner of the _History_ view). – howlger Nov 09 '18 at 00:07
  • i don't see the button you are talking. – user9735824 Nov 12 '18 at 15:56
  • Here, the button to the right of the _Compare Mode_ button: https://www.youtube.com/watch?v=13dka9ut-xs&t=120s – howlger Nov 13 '18 at 07:18

1 Answers1

5

Using Eclipse/EGit:

  1. Open the "Git Repositories" View
  2. Make sure branch1 is checked out (respectively the branch you want to update with changes of the remote master branch).
  3. Right-click the repository you're working on and click on Fetch from Upstream. This will fetch information about new commits on the remote repository (in your case the new commits that were added to the master branch after your branch (branch1) was created). enter image description here

  4. Expand the Remote Tracking node and right-click the master branch. Select either Merge or Rebase on. Both options update your branch (branch1) with the changes that meanwhile were added to the master branch.enter image description here

The difference between Merge and Rebase on: https://stackoverflow.com/a/16666418/5207900

Marteng
  • 1,179
  • 13
  • 31