The easiest way to start using git is to create new repository on the web page.
On the web page you can find url of you newly created repository, for example:https://github.com/matjaz99/Test2.git
Inside Eclipse open Git perspective (make sure you have egit plugin installed). Click on the 'Clone Git Repository' button. In new window enter the url of repository and press Next.
Select branch if needed and press next.
In next window enter the local directory where repository will be created on your disc (probably some workspace).
You should see your repository (project) in Git Repositories window in Eclipse. Also
project directory was created on disc in specified location (workspace).
To import it into Eclipse as a project, right click on the repository and select Import projects...
Use a wizzard to import the project.
Happy coding until it is time to commit the work into remote repository.
You can access Git functions by right clicking on the project and point to Team submenu.
Choose the first one - Commit... In new window enter a comment (mandatory), select files to commit and press 'Commit and push'.
It is important that you choose 'Commit and push'. 'Commit' only stores changes in local directory on your disc, while 'Push' actually uploads the files to the remote repository. 'Commit and push' does both at the same time.
If commit is successful, you will be notified with message like this:
Git Repository view should loog like this:
You can also commit the changes from the Git Staging window in Eclipse. Drag and drop files you need to commit from 'Unstaged changes' to 'Staged changes'. Enter comment and press 'Commit and push' button.
When the code is ready to prepare a release, you need to create a tag. A Tag will store all current files and modifications. To create a Tag open Git Repository perspective and expand project repository. Right click on Tags and select Create Tag... In new window enter the name of the tag - usually a version of release.
New Tag is created locally. You need to push it to remote repository. Do this by right clicking on the tag and select Push Tag... In new window select a repository (already selected) and press Next button.
In next window enter the Target ref name. If you have no idea what this is, just enter something like: refs/tags/<tag-name>
Press Finish to commit the tag to remote repository.
To delete a tag, right click on the tag and select Delete tag... I am not sure if you can commit deleted Tag to remote repository. If you prepare new release and you want to use the same tag name, check Force Update checkbox.
If the customer requires a major modifications in your code or you are just switching to new technology (eg. from JSP to JSF), you create a new branch in your repository and continue developing under a new branch. You can switch to old branch anytime and do some bug fixes or whatever in an old branch.
To create a new branch right click on the project, point to Team submenu and then Switch to... submenu. Choose New branch... Enter a branch name. This will create a copy of existing project in new branch.
Next you need to push new branch to the remote repository.
Now the repository should look like this:
Keep coding and commiting...
Compare and replace
To compare a modified file with the one in repository, right click on project, goto Compare with... submenu and select HEAD revision (the last commit) or any other revision.
In the same way you can choose Replace with... HEAD revision to revert to the last commit (or any other revision).
To merge two branches first checkout the branch you wish to merge to (eg. master). Right click on master branch and select Merge... In window select which branch you wish to merge into master branch.
Hint: how to commit empty directory
To commit empty directory to git you need to create file .gitignore in that directory and commit it to the server. The .gitignore file must contain: