A Short Tutorial on Eclipse/EGit/GitHub

Step 3: Clone the Repository

Back at GitHub, go to this url: https://github.com/CP365-B6-2011/Final_Project Copy the url on that page (where it says SSH|HTTP|Git Read-only). We need it to clone.

Go back go Eclipse, and go to File -> Import. Expand the Git category, and click “Projects from Git”. This will pop up a window with all of your configured repositories, which at this point is none. Click “Clone” at the top right, and it should autofill the fields with the URL we’ve copied. If it doesn’t, paste it into the url field. Under protocol, go ahead and change it to SSH, and click “Next”. It’ll try to authenticate to the server, and if you’ve set up your SSH key correctly it’ll succeed! Enter any passwords it asks for and continue. It’ll pop up a window with the various branches on the server; you can clone any of them that you want, but I recommend that you keep your team’s code in a branch off of master. Definitely clone master. Once you’ve selected the branches you want, click “Next” and it’ll ask you for a directory to put it into; put it wherever you want to. Don’t change anything else. That will give you a copy of master that we can work on, and everything should be kosher.

Back to the main Import from Git screen, select the repository you just cloned and click “Next”. Leave the defaults on the next page, and click “Next” again. Check “CP365_FP_GIT” and click “Finish”. What do you know? You have a new project, with Git and everything!

Step 4: Working on the Project

If you didn’t quite catch my presentation, there’s some OpenOffice Impress slides you might want to look at here.

It’s really best if each team works in their own branch. I’ll set some branches up for each team later this afternoon, and I’ll show you how to get them at our meeting. Until then, if you’re really skippy and doing work already, feel free to work in master.

As far as working goes, do your work on whatever you’re doing, then add our files by holding CTRL while clicking on each of them; right click on one of the selected files; go to “Team” -> “Add” and it will add your files to the repository. Immediately after doing that, commit by going to “Team” -> “Commit”. Be sure to enter useful messages, we want to be able to see what’s going on! When you’ve got en enough of your work done that you feel like it should be shared, go to “Team” -> “Push to Upstream”. If it gives you a failure on the popup window, pull from upstream before pushing; it probably means someone pushed before you did. Well, that’s all for now. Check back for more in a later post!

Advertisements

9 thoughts on “A Short Tutorial on Eclipse/EGit/GitHub

    • It really helps to have Eclipse open while I’m writing the walkthroughs. I try to keep the wording exactly to what you’ll see; I’m glad it helps! Thanks for the compliment!

  1. Great post. But, the issue I have is that I have *many* Eclipse projects that I want to “push” to Github and then use Github from that point for source control. Any tips on how to accomplish that?

    • It’s actually pretty straightforward to do that, luckily enough! First, right click on the project in Eclipse and select Team -> Share Project -> Git and select the project. If there’s already a Git repository there, it’ll allow you to checkmark the project; if not, select “Create Repository” and leave the default path. Click Finish.
      Now that EGit knows about your project, you can right click it again, go to Team -> Remote -> Push, and enter the details of your GitHub repository. The host is github.com, repository path is yourusername/yourrepo, protocol is ssh, user is git and password can be left empty; you’ll be prompted for your SSH private key password at the next window. Enter your password, select the branch you want to push (probably HEAD) in “Source ref” and the branch you want to push to in “Destination ref” (again, probably HEAD). Once you’re ready, hit Finish. It should push your changes and be available on GitHub! Unfortunately, ad-hoc setting of the remote tracking repository (aka, the one you pull/push to/from) isn’t supported yet by EGit. You’ll have to go to the command line to fix that if you want to keep the current project. Alternatively, you can just pull the source you just committed (you committed everything, right?) and create a new project from that based on the instructions in the tutorial. That will set up the RTB correctly.

      Hope that helps!

      • Yes, that does help. I need to unpack this statement however:
        “Unfortunately, ad-hoc setting of the remote tracking repository (aka, the one you pull/push to/from) isn’t supported yet by EGit. You’ll have to go to the command line to fix that if you want to keep the current project.”

        I am not sure what that means exactly (I am new to Git). Does that mean I cannot incrementally push the project to GitHub for “Safekeeping”? or does that mean I am not able to track the changes incrementally or?

        And what would be the command line “fix” for this?

        Thanks

      • It means that you’ll have to do the above “Push” sequence each time you want to send your updates to the remote repository. If you want to fix it from the command line on Linux, you’ll have to use the following commands:

        git remote add origin
        git config branch.master.remote origin
        git config branch.master.merge refs/heads/master

        This will let you push/pull using just git pull and git push to the remote repository; EGit should pick up on the configuration changes automatically and use them. Let me know if it doesn’t!

  2. Pingback: Eclipse and Github Tutorial « Missing Link

  3. Hey, I’m having a bit of trouble, I follow your instructions but when I get to the point where it’s asking me to File->Import then select Git, I don’t see a Git category. I only see General, CVS, Install, Plug-in Development, Run/debug, Team, XML.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s