segunda-feira, 24 de setembro de 2012

Tutorials - Using GitHub and EGit in Eclipse part 2

If you notice the title I'm mentioning using GitHub that's because it is my porpoise to also do some command line operations as well as explain the concepts behind GitHub.

Ok now that the EGit installation is complete is time to use to upload a project. So for starters its better to get good inside of GitHub working architecture. The first thing and one that was kind of hard for me to get is that we have a local repository and remote one. Now the tricky part is that we must always first make a commit to the local repository and only then you can push it to the remote one. What at first got me really confused is that in other SVN/CVS (like tortoise, which by the way O am not sure if still works like this been some years since last use it) systems you don't have to do this intermediary step. Once you've changed a file in you're local machine and you made a commit things woud go to the remote  repository.
I took this schema from Wikipedia and it represents quite well what's going on in a git repository. First you create a project (your working directory) then you have to create a repository by command line or by EGit (will show this bellow). By creating a repository now you will have an extra folder which is maintained by Git (it's actually a .Git folder)  and the block Index in the picture is an Head file in that folder. Now every time you make an add command the code/folders of your source will become staged, or a registry will be inserted in the Head file informing the changes you are about to do this way git keeps a track of your commits. Once you've done with staging you can commit by inserting a nice message on what you're actions were and finally push it to the remote server. The push will only be allowed your local repository is in sync with the remote one, so you might need to do a fetch command and check the differences and a pull to actually get those files that you don't have locally or that have been changed.



Maybe the first part would be better at the end I think you should re-read it after finishing the procedure. For the sake of completion I leave the images bellow on how to create the new project (standard Java on Eclipse...) to be under version control.





Now the EGit stuff comes into play, it is pretty straight forward wizard and allows to create the local repository. Pressing the second button over the project root folder on the Package Explorer window  you should be able to see Team and a Share option inside it.  This will open the wizard.



Select Git and on the next screen press create. This will show the folder where the repository will be created and the name you want to give to it.

Under the Project pane there is a checkbox if you leave it selected it will  make that your working directory to be transferred to the repository folder.
In the end you should get a project with an question mark over it's files meaning there are unstaged changes.
If you have installed the GitHub command line mode installed and you can get it like this for Ubuntu.

$ apt-get install git-core

Or for other systems check it here. It is possible to check the repository by navigating there using the command line. And you can see that there can be as many repositories as you want, also they can be connected to any number of online repos and even better you can have as many branches  as you want (that will be another tutorial). So you can see from my Terminal that I am navigating to Git folder where I have all my local repos stored if I run a git status outside a repo the output will be error but as soon as you are inside a repo git command immediately starts to make sense of it.

quarta-feira, 19 de setembro de 2012

Tutorials - Adding GitHub to Eclipse

To simplify life using GitHub one can recur to EGit a great tool that can make interaction with GitHub much more intuitive and integrated for those who like to work with IDE's instead of using the terminal!

You can find most of this tutorial on the EGit Eclipse page but I had some features of my own but allot of stuff is just plain copy paste.

Installing EGit into Eclipse

After downloading Eclipse (any version can be plugged with this feature) and start it go to preferences:

Select Install New Software. On the new screen type http://download.eclipse.org/egit/updates on the work with: TextBox.


Click Next and confirm your selection in the following window pressing Next again. Finally, accept the terms of license agreement and click Finish to start the installation. After the installation has finished, restart Eclipse to work with EGit.





EGit Configuration
Every commit in EGit will include the user's name and his email-address. These attributes can be set in the Preferences-window Window => Preferences. Navigate to Team => Git => Configuration and hit the New Entry... Button. Enter user.name as Key and your name as Value and confirm. Repeat this procedure with user.email and your email-address and click OK in the Preferences-window.

What else to do with this feature, this key-value pair?
Why not use it to store parameters for your workflow scripts? Here's some ideas.
  • The locations of CSS and JS files to be minified
  • Compilation output directory
  • The latest version release number (if your not a tag fan)
  • Feature branch meta data (owner, decription, etc.)
  • A list of deployment servers
More on this here.

So this finishes the installation and setup of EGit on Eclipse (well not really because we still need to push files to the SVN server on this case GitHub and this requires configurations on both sides).

Next tutorials will be more interesting as I am describing some concepts of git that normally are confusing at the beginning.