Beginner Tutorial for EGit

Git has been around for a while and there are tutorials everywhere for it. EGit is a plugin for Eclipse that integrates many of the same features but it’s much more Eclipse and Android friendly. Here’s a tutorial for contributing to a Repo that was already created.

Set Up an Account

Go to https://github.com and set up an account

Get Eclipse Set Up

You need a new version of Eclipse. Google’s SDK (http://developer.android.com/sdk/index.html) and new versions of Eclipse have eGit preinstalled.

You can check by right clicking the blank space in the package explorer pane then selecting import. Git should be an option. If it’s not then you will either need to update Eclipse, get a new version of Eclipse, or install the EGit package http://www.vogella.com/articles/EGit/article.html#eclipseinstallation

Now you want to add your name and email address to make pushes easier: Click Window -> Preferences -> Team -> Git ->Configuration

Here you can add your name and email to the user section so we can track who’s done what. For now select Add Entry then enter user.email for the Key and your_email@email.com for the Value then click OK. Add another Entry with user.name for the Key and  your FirstName LastName for the Value.

Import Repo

Right click the blank space under package explorer

Select -> import

Click the drop down folder for Git

Select -> Projects from Git

Next

Select -> URI

Next

URI: https://github.com/user_name_that_created_repo/repo_name.git

Host: github.com

Repository path: /user_name_that_created_repo/repo_name.git

Authentication

User: Your User Name

Password: Your Password

Next

Make sure master is checked

Next

The Directory destination can be wherever you like but make sure the folder is the same name as the Repo name

Leave everything else alone

Next

Select Import existing projects

Next

If it works then you should be able to select the project you want to import.  Selected and then you are finished

Tips for Importing

Sometimes when you are done importing there will be a errors. Frequently these are easily solved. Check the console and it may tell you something like right click the project folder, select android tools, and then fix project properties just follow the instructions and you should be good. Also, try closing Eclipse and reopening it which can sometimes solve some errors.

If you make a mistake you may need to delete the folder. If you do it in Eclipse it may or may not actually delete the folder depending if it’s still tying up a resource. If it doesn’t delete the file then you can delete it by first closing Eclipse, finding the file in the windows explorer (or whatever you use) and delete it, then reopening Eclipse and deleting the file again.

Push and Pull

The first rule is to never do a Push unless you first do a Pull. A Push will only update the files you have changed so you will only run into conflicts when two users are updating two files at the same time. If you push a file at the same time a different user pushes the same file you will either create a branch or the Push will be denied and you will have to do conflict resolution. Conflicts can take more time to resolve then the time you spent coding you did so try to avoid them.

To Pull

Right Click the Folder in the Package Explorer Pane

Highlight Team

Click Pull

It will update the files.If there are conflicts you will be notified at which time you will have to correct them but this is beyond the scope of this tutorial.

Conflicts are troublesome and time consuming so always do a Pull first.

To Push

Right click the folder in the Package Explorer Pane

Highlight Team

Click Commit (Git requires that you first push then commit to the changes however EGit has the option to run the two together)

Here you need to add a commit message so you can trace what’s been done. If you added your name and email address earlier then EGit will add the signature for you.

The files you have changed will be in the Files list (it should ignore the system generated files if the .gitignore file was configured correctly). Make sure all the files are checked.

Click Commit and Push you will only select Commit if you are doing the Push and Commit separately

You will get a confirmation message. Just click Ok. If there are conflicts it will give you an error and you will have to resolve them before you can do another Push.

Tips for Pushes

If .gitignore is not used or not configured correctly then it will want to update system generated files. Do not update system generated files. You should never have to push the files in the bin and gen folders or the files with the following extensions .apk, .ap_, .dex, .class, and the local.properties file. If you push these files they will always lead to conflicts with the other users or other computers you may use. Instead make sure you configure the .gitignore file when you create the Repo, doing it later is much more difficult.