All collaborators must make sure to have EGit installed in Eclipse. You can check this by going to Help > Install New Software and clicking on “What is already installed?” You should see it in the list as ‘EGit Import’. If you don’t see it, then go to Help > Eclipse Marketplace and do a search for “egit”. Install EGit and restart Eclipse.
Make sure you have a GitHub account.
These instructions assume you have Git installed. If you don’t, then click here for instructions on that.
In Eclipse, delete your existing project by right-clicking on the project in the Package Explorer pane, but make sure “Delete project contents on disk” is unchecked. If you’re starting on a new project, create a new project as you normally would and then delete it as explained previously. Basically, we want to keep the project on disk, configure it for Git, and then import this Git-configured project into Eclipse.
In your GitHub.com account, create a new repository and name it the same as your project. It will then give you instructions on how to “Create a new repository on the command line”:
These are a set of Git commands that configures the project on your local machine to “fork” the newly-created GitHub repository. This means you have to navigate to your project, as follows.
Keep those provided Git commands aside and in Terminal, navigate to your project and you should see some hidden project files like so (using ls -a),
You can see that it has not been configured for Git yet, as there’s no hidden .git folder. Use those Git commands to configure the project. It will ask for your GitHub username/password. After configuration, you should see the hidden git directory in there:
(If you look in that .git folder, you’ll find version control files such as HEAD and config.)
Use the remaining commands under “Push an existing repository from the command line”.
Now the project is ready for committing and pushing/pulling.
In Eclipse, click File > Import and choose “Projects from Git”.
Subsequently, select “Local” when choosing a Repository Source. Then select your Git-configured project (which should show up in the list) and finish with the import wizard:
The project should show up in Package Explorer. Right-click it and click Team > Commit. Check all the files you’ll need to collaborate on (probably all except .DS_store). There should now be an ‘up’ arrow beside the project name after a commit.
Now push it to the repository so other collaborators can pull in these files.
To push, right-click the project name and Team > Push to Upstream.
Finally, you have to add all collaborators in your GitHub.com account under the repository settings:
Everything should now be ready for collaborators to clone the repository into their local machines.
Get the clone URL from the lead collaborator. It is found on GitHub.com where the repository is living. You should see it on the bottom right side of the webpage:
Copy the HTTPS clone URL. You’ll need this when you clone the project into your local drive, as follows.
In Eclipse, click File > Import and choose “Projects from Git”. Select “URI” as the Repository Source and paste the HTTPS address in the URI field. Keep the default values and click Next. (Don’t worry, you’ll get to choose the destination directory in a later dialog prompt.)
In the Branch Selection dialog, keep “master” checked and click Next.
In the Local Destination dialog, choose where you want the project to live on your local drive and click Next. The repository has been cloned to your drive.
In the dialog Wizard for project import, check Import existing projects (because we just cloned it from GitHub) and click Next.
In the Import Projects dialog, check off “Search for nested projects” to make the project show up in the list. Make sure the project is checked and click Finish.
The project is now on your local drive and ready for pushing/pulling to/from the remote repository on GitHub.
Commiting, Pushing and Pulling
Whenever you make significant changes to the code, commit it by right-clicking the file in Package Explorer and clicking Team > Commit. There should be an ‘up’ arrow and a count number beside the project name when commite is made.
Once you’re happy with all your commits, you have to push it to the repository so others can pull in those changes.
To push, right-click the project name in the Package Explorer and click Team > Push to Upstream.
Always push your commits before closing Eclipse so the same changes are made in the remote repository. Whenever you revisit the project, always do a pull before starting to code.
To pull, right-click the project name and click Team > Pull. This should update your code with the latest changes.