Git is a very popular Distributed Version Control System. It has Become the choice for most of the open source projects due its simple yet powerful features. There are many online articles to get started with Git, but if you are in a hurry, here I am explaining how to set up a Eclipse project which maps to a public Git repository. Cause I took some time to figure it out 🙂
Create a GitHub account
Go to https://github.com/ and create a free account with your email ID
Create a new repository
Once you logged in to GitHub you can create a new repository by giving just a name, say “NewRepo”.
Install Git on your machine.
Go to http://git-scm.com/downloads and choose your installer. This will install the Git shell (CLI) and GitHub (GUI)
Clone the repository to your local machine
Now lets download the remote GitHub repository and create a clone in your local machine. Later on, any changes you make locally can be pushed to remote repository and vice versa. Open Gits Shell (CLI) and navigate to your Eclipse workspace directory. Execute following command from the workspace directory.
git clone https://github.com/{your ID}/NewRepo MyEclipseProject
This will create a clone of the remote repository (as of now empty) in your local machine.
Create a new Eclipse project
Create a new Eclipse Java project by selecting the cloned directory as the location.
This will create the .project, .classpath and src directories inside your local repository automatically. You can keep adding your source code (Java classes, scripts, etc.) into this project now, through Eclipse.
Commit and push your changes
Once you are done with your coding, you can push all the changes you made locally in your Eclipse to your remote GitHub repository. From the Gits Shell navigate to the cloned directory (MyEclipseProject) and execute the following commands
git add .
git commit -m “my comment”
git push
That’s it, Now you can check your remote repository in GitHub, all the code you have written locally in Eclipse will be available there.
Update
Cloning git repository & Pushing to GitHub can be done through Eclipse as well with the Eclipse Git plugin. Install it from here http://www.eclipse.org/egit/download/ . Then you will have new option to import Git project when selecting import in Eclipse. Also right click on the project and select “Team” in Eclipse or simple press Ctrl + # to commit and push, its that easy 🙂
If you find this information useful, please share the link.