Tuesday, November 17, 2020

Connecting Your Eclipse Project to Github

 

OK so I have a relatively complex Java and MySQL database project that was developed in Eclipse EE using Tomcat. I want to now make it available on GitHub. So how do I do that?

Here is a really great YouTube tutorial that shows exactly how to set up your project to get it ready to commit to GitHub, as well as how to add the proper configurations to your project so that pushing stuff to and pulling stuff from the GitHub repository goes smoothly:

https://www.youtube.com/watch?v=HuhJ22oHyfc

  1. So, start with a completed project in Eclipse.
  2. Make sure you have Git for Windows installed, and of course a GitHub account.
  3. First thing you do is creates a local repository on his own machine.
  4. Right click on project > Team > Share Project... and this opens the Configure Git Repository dialogue
  5.  On the Configure Git Repository dialogue, click the Create button... this opens the Create a New Git Repository dialogue
  6. Now, in the Create a New Git Repository dialogue there is a 'Repository directory' field
  7. The value of the 'Repository directory' field defaults to 'C:\<whatever your path is>\git\repository'
  8. Change that to 'C:\<whatever your path is>\git\Local<your project's name>'
  9. Click Finish on the New Git Repository dialogue and then click Finish again on the Configure Git Repository dialogue. (Eclipse will have now moved your repository into a different location)
  10. Now, you need to enable some Git stuff on your project.
  11.  Go to Window > Perspective > Customize Perspective ... this opens the Customize Perspective dialogue
  12. On the the Customize Perspective dialogue, click the Action Set Availability tab.
  13. On the Action Set Availability tab, select all the Git options, then click Apply and Close. 
  14. Now you will see at the top that you have a Git menu, as well as some new Git buttons in the tool bar.
  15. Next, select Window > Show View > Other ... this opens the Show View dialogue.
  16. In the Show View dialogue, expand Git. In the Git drop-down, control-click 'Git Repositories' and 'Git Staging.'
  17. While still in the Show View dialogue, expand Team and control-click 'History.'
  18.  Now, all three of those views are open in the bottom of the Eclipse IDE.
  19. Now, to commit the project for the first time to GitHub, right-click on your project > Team > Commit ... this updates the Git Staging view at the bottom of the IDE
  20. In the Git Staging view at the bottom of the IDE, click the double arrows (the ones that when you hover over them say 'Add all files including non-selected ones to the index')
  21. This moves all your project files from the Unstaged to the Staged box. 
  22. In the Commit Message box, type 'Initial commit.' Remember, this is all gonna be public so keep it PG.
  23. DO NOT click the Commit and Push Now button. Instead, start out by clicking the Commit button.
  24. Now, click on the GitHub Repositories view.
  25.  Right-click on the repo that appears in the GitHub Repositories view > Show In > History 
  26.  This is the point where you should go online to your GitHub account and create a new repository for this project. 
  27. Leave it Public and DO NOT select any of the Initialize Repository options. Instead, just click Create Repository.
  28. On the GitHub 'Quick Setup' page, copy the url to your repo (it will look something like 'https://GitHub.com/olddognewtrix123/ContactManager.git')
  29. Now you need to do a little more work on your project so that when you finally do the initial commit to GitHub, things will go smoothly.
  30. So, back on the GitHub Repositories view, expand your repo, right-click Remotes and select Create Remote - this opens the New Remote dialogue.  
  31. On the New Remote dialogue, leave everything at default and click OK - this opens the Configure push for remote dialogue.     
  32. On the Configure push for remote dialogue, click the Change button - this opens the Source Git Repository dialogue.
  33. The Source Git Repository dialogue should already have your GitHub URI selected.
  34. The URI field should have something that looks like 'https://GitHub.com/olddognewtrix123/ContactManager.git'
  35. The Host field should have something that looks like 'GitHub.com'
  36. The Repository path field should have something that looks like '/olddognewtrix123/ContactManager.git'
  37.  On Source Git Repository dialogue, type in your GitHub username and password, then click Finish.
  38.  Back on the Configure push for remote dialogue, click the Advanced button ... this opens the Push Ref Specifications dialogue. 
  39.  On the Push Ref Specifications dialogue, drop down Source ref and select 'master[breanch],' then click Add Spec.
  40.  On the Push Ref Specifications dialogue, select the 'Save specifications and origin configuration' box, then click Finish.
  41.  Back on the New Remote dialogue, click Save. 
  42. Now, click the 'Push current branch to upstream' button on the toolbar in the IDE (it is the one with the up-arrow)
  43. The machine thinks for a bit, then opens the Pushed to LocalContactManager - origin doalogue.
  44.  On the Pushed to LocalContactManager - origin doalogue, just click Close.
  45. Go back to the repository on your GitHub account. Hit F5 and you will see a folder for the initial commit of your project. 
  46. Now, that's all set up to push stuff to GitHub. But what if you want to pull stuff (like if you decide down the road to have collaborators making changes to the GitHub repository)?
  47. Back on the GitHub Repositories view, expand origin then right click on the fetch configuration (the one with the down-arrow next to it) and click Fetch Configuration ... this opens the Configure fetch for remote origin dialogue. 
  48. On the Configure fetch for remote origin dialogue, click Advanced, select 'master [branch],' Add Spec, Finish and then Save.


  


       

No comments:

Post a Comment