2

How do I dot the following in Eclipse?

I have created a Android app project in Eclipse and I have put this under version control using eGit and BitBucket (again I don't know if this is the best way to describe it as I'm new to version control). I have written some code and made several commits so far. I have invited a friend who has joined the project. Last night they changed some of the code.

Today I fire up Eclipse and want to continue working on the project, but want to start from where they left off. I right click on the project and go to Team -> Synchronize (simply because this seemed the most logical step to me). Nothing happened as I feared.

How to I get the latest version of the working code onto my local machine? And when I am finished my work, do I just commit as I have been doing by right clicking project and then going to: Team -> Commit followed by Team -> Push to Upstream?

Mr_and_Mrs_D
  • 32,208
  • 39
  • 178
  • 361
heyred
  • 2,031
  • 8
  • 44
  • 89
  • Found the solution here as posted by VonC. http://stackoverflow.com/questions/15284706/eclipse-egit-current-branch-not-configred-for-pull – heyred Sep 23 '13 at 11:32

3 Answers3

5

Within Eclipse, start using the Git Repository Explorer perspective, and the Git Staging View.

The repository explorer shows your clone, allowing you to see your branches, your change history etc. You can right mouse on your clone's name and choose pull. This will fetch changes from the Bitbucket server and then merge them to your local branch.

Note you should not pull until you have either stashed any locally modified files, or have committed them to your branch. If the pull conflicts with any local changes the action will be rejected.

As you are sharing a branch with other people you should consider modifying your local (master?) branch via Configure Branch... to enable the Rebase option. This means when you merge remote changes over your local branch, any outgoing commits are replayed over the top of the incoming ones. It means when you push you avoid merge points which can clutter up the history. Encourage other people working in their own repos to do likewise.

Secondly, when you are committing changes, learn to use the Git Staging view. This makes it easy to drag and drop changes and commit them in a single go. You can also do this from Team | Add and Team | Commit... but IMO this is far more clumsy.

When you are ready for others to see your committed changes you must push them. Normally you would either right mouse on a project and choose Team | Push to upstream or go to the repository explorer, right mouse on the clone and choose Push to Upstream. If necessary you may have to pull before you can push because the server will reject changes if they do not satisfy merge

This is the basic workflow of using Git within Eclipse. As a general point, also ensure your version of the EGit plugin is at least 2.3.1 or 3.0.1 depending on your version of Eclipse.

locka
  • 5,809
  • 3
  • 33
  • 38
1

you can not get the newest code that be changed by your friend is maybe because after he changed but he didn't commit..and now although you cannnot get the changed code but you can also commit your changed code.because when he commit...maybe errors shows then your friends will change his code base the code you have commited.

Clover Wu
  • 29
  • 4
  • No he definitely pushed a commit because I am able to view the updated code on BitBucket - the code he changed and committed. And if I'm understanding your second point correctly, I shouldn't commit now because it may cause conflicting errors? Yeah this is what I am afraid of. I don't want to change the code and commit before getting latest version. – heyred Sep 19 '13 at 11:13
  • Just tried Team -> Fetch From Upstream. Here I can see their commit. I select this and click OK but nothing happens. Is there something I'm missing or not doing first/after this step? – heyred Sep 19 '13 at 11:33
  • Do I maybe have to Team -> Commit after I Team -> Fetch from Upstream? So I commit the Fetch to my local repo? In essence do a commit to repo in reverse? Hesitant to try this in case I overwrite their code. – heyred Sep 19 '13 at 11:38
1

I would recommend against using eGit as I commented here.

If on windows download and install msysgit

Then Right click on your eclipse project folder - select Git Bash here and issue

$ git pull

The problem with fetch is that it only fetches - pull fetches but also merges the commits it fetched

Community
  • 1
  • 1
Mr_and_Mrs_D
  • 32,208
  • 39
  • 178
  • 361
  • Thanks for the answer, but I am trying to stay away from command line as this will create even more problems for me as I have no experience in this at all. I did find the answer though after hours of trying everything. Answer listed with link to solution. Thanks again for the help. – heyred Sep 23 '13 at 11:35
  • @HansMoolman: You will have endless problems with eGit - I am not using the command line either - but for some things it is recommended - and anyway you can use git gui for pushing. Trust me you either learn msysgit or you are entering a world of pain. Git is really awesome but _there is a learning curve and ignoring it you will end up loosing your work._ You've been warned. Btw post your answer as an answer and accept it - that's the proper thing to do – Mr_and_Mrs_D Sep 23 '13 at 11:41
  • Sorry thought I had posted the answer. But thankfully I did not as the answer I thought I had caused more problems down the line. You may be right re. eGit. I will try one more solution and give msysgit a go. – heyred Sep 25 '13 at 16:26
  • @HansMoolman: It is very simple actually - and if you haven't edited the files then you won't have to merge manually (this can be tricky but this is a part of _git_ (or _version control_ in general) _not_ msysgit, egit etc). Please do and post your results – Mr_and_Mrs_D Sep 25 '13 at 16:34