Git and EGit for Beginners
First, understand that a "commit" in Git is no longer a remote operation. Git maintains a complete copy (clone) of the repository, so your commits no longer go on the server. Changesets are pushed to the server. You commit locally.
- If you're not using Eclipse Juno, now is a great time to upgrade
- Install EGit: Help > Install New Software, then Work with: choose Juno - http://download.eclipse.org/releases/juno
While you're there, install the PDT tools from Programming Languages.
Cloning Git repositories as new PHP projects
- Switch to the PHP Perspective (Window > Open Perspective > Other > PHP) then go to File > Import... Expand Git, and choose Projects from Git > Next
- This will allow you to create a new PHP project with the Git repo contents inside.
- Repository Source: URI > Next
- Enter the URI to the repo, as I did for articles in this example.
- Next, Next. Cloning may take a while -- don't forget, you're getting a complete clone of the repository.
- Use the New Project wizard (Finish), and choose a new PHP project from the Select a wizard dialog. Give it a name (I called mine "articles") > Next > Next > Finish
Repeat these steps for other web content you may need to connect to.
You'll end up with a new project, similar to the screenshot. The information between the square brackets is information about the Git repo.
Changing a file, committing, pushing
REMEMBER: a "commit" in Git is a LOCAL operation on your local Git clone. Committing does _nothing_ on the server -- that's what a PUSH is for!
In the screenshot below, you can see I changed the file "about.xml" since it has a change marker (>) in front of it.
- Right-click the file (or the parent folder, or the entire project) to commit the change(s) to your local repo. > Team > Commit
- Make sure all the correct files are checked, enter a commit message, and presss Commit. This is similar to CVS.
- PLEASE NOTE: The author and committer information must match that of your Eclipse Foundation committer record! See below for info on changing this.
- When the commit is complete, you'll notice the change markers are now gone. However, next to the repo, there is a marker to indicate that you have one outgoing change. Push it now: Right-click the repo > Team > Push to Upstream
- You'll also notice that the Team menu has a Pull option to pull changes in the remote repository. Always pull changes before editing files.
No one really cares what your name and email address are when you only commit locally. However, if you want your committed changes to be accepted by the Eclipse Git servers, the Committer information must match your committer record. To set them correctly in Eclipse:
- Window > Preferences
- type "git" in the search area
- Go to the Configuration item, press Add Entry and enter the information as depicted: