It does sound simpler than it actually is, but configuring eclipse and Egit to work with github has quite a few bumps. This is meant to be a quick guide and focus on the problems along the way instead of the process, since there are already good guides out there that focus on the entire process (see the references in the bottom, specially [3]). For the record, I'm using:
This is fairly straight forward. Go to your account on http://github.com/, click on "Dashboard" (top right) and then "Create a repository". Just follow the simple instructions and you'll get an address for the repo that you'll use later on.
Installing git
That's pretty easy. Just:
Github provides a pretty good tutorial on generating ssh keys [1], but I'll reproduce the main steps to make it work. Refer to [1] for a more detailed explanation.
Create .ssh folder:
Installing Egit
If you are running Eclipse 3.6+, you can install Egit through the marketplace. In Eclipse, go to Help -> Eclipse Marketplace... , search for Egit and install it. Restart Eclipse afterwards. If you are not using Eclipse 3.6+, refer to Egit documentation for your eclipse version [4].
Configuring Eclipse
Here, we need to configure SSH.
Final step is to push your project to your remote repository on github.
Easier than pushing is checking out a project.
After configuring eclipse, you should probably set a non-empty passphrase to your ssh key. It is not the scope of this post to discuss why you shouldn't leave your passphrase empty, but here is how:
Hope this was helpful. Feel free to comment or add any info.
[1] http://help.github.com/linux-key-setup/
[2] http://help.github.com/troubleshooting-ssh/
[3] http://blog.doityourselfandroid.com/2010/08/14/git-github-and-egit-eclipse-integration/
[4] http://www.eclipse.org/egit/
Cheers,
Lucas Piva
- Eclipse 3.6 (codename Helios)
- Ubuntu 10.10
- Create a repository on github;
- Install git;
- Configure ssh keys.
- Install Egit in Eclipse;
- Configure Eclipse;
- Push your current project to github repository;
- Check out (pull) project from github.
This is fairly straight forward. Go to your account on http://github.com/, click on "Dashboard" (top right) and then "Create a repository". Just follow the simple instructions and you'll get an address for the repo that you'll use later on.
Installing git
That's pretty easy. Just:
$ sudo apt-get install gitYou can also install git-doc and git-gui if you like. You should also set your username and email to properly sign your commits:
$ git config --global user.name "your name"Configuring ssh keys
$ git config --global user.email "youremail@yourdomain.com"
Github provides a pretty good tutorial on generating ssh keys [1], but I'll reproduce the main steps to make it work. Refer to [1] for a more detailed explanation.
Create .ssh folder:
$ mkdir ~/.sshIf the directory already exists, it will simply throw an error and skip. Generate rsa key pair:
$ ssh-keygen -t rsa -C "youremail@yourdomain.com"The -C is just an optional comment. By default, it will be saved in ~/.ssh/ directory. For now leave the passphrase empty! This is important, since Eclipse has a bug handling passphrase protected keys. We will give it a passphrase later. Now, go to your account on github, go to "Account Settings" (top right), than click on "SSH Public Keys" on the left menu and "Add another public key". The tittle should be some comment that identifies which computer this key is from (such as "Home-desktop"), and the "key" should be the exact contents of the file ~/.ssh/id_rsa.pub. There is a neat trick using xclip to copy the contents of the file to the clipboard without messing anything (such as adding whitespace and newlines):
$ sudo apt-get install xclipThose commands copy the contents of the file to your clipboard. Now just ctrl+v in the "Key" box in github and you should be done. To test everything is working, try running:
$ cat ~/.ssh/id_rsa.pub | xclip -sel clip
$ ssh git@github.comAnd you should receive a message that looks like:
Hi user! You've successfully authenticated,One possible problem here is getting a message that looks like:
but GitHub does not provide shell access.
Connection to github.com closed.
Permission denied( publickey).If you do, try manually adding your generated key to ssh path and checking permissions are correct:
chmod 700 ~/.ssh/id_rsaI had this problem because I regenerated the pairs a few times and ssh somehow couldn't find my key anymore. If that doesn't work, please refer to git troubleshooting guide [2] for other possible problems.
ssh-add ~/.ssh/id_rsa
Installing Egit
If you are running Eclipse 3.6+, you can install Egit through the marketplace. In Eclipse, go to Help -> Eclipse Marketplace... , search for Egit and install it. Restart Eclipse afterwards. If you are not using Eclipse 3.6+, refer to Egit documentation for your eclipse version [4].
Configuring Eclipse
Here, we need to configure SSH.
- Go to Windows -> Preferences and filter SSH. Select SSH2 on the left tab (should be under General -> Network connections).
- Check that SSH2 home is set to /home/<yourusername>/.ssh and id_rsa is in Private Keys.
- On Key Management tab, click on Load Existing Key... and select your id_rsa (private) key under ~/.ssh/id_rsa. If your key has a non-empty passphrase, eclipse will not be able to load it, even if you provide the correct password.
- Now, just save it in the same location you loaded it from, confirm empty passphrase, overwrite it, apply and click ok.
Final step is to push your project to your remote repository on github.
- Finally, select the project you want to push to your created repository, right click it, go to Team -> Share Project... and select git.
- Select your project, click on Create Repository and Finish. Now you should be able to commit and update changes to your local git repository.
- To push it to your remote github repo, right click your project, select Team -> Remote -> Push...
- Fill the URI with your project SSH address, which is shown when you enter your repository page on github.
- Select ssh protocol, user is git and empty password.
- Cross your fingers, hit next. If it doesn't work for some reason at this point, try restarting Eclipse (it worked for me after restart).
- Select Source Ref and Destination Ref (basically the branch), click on Add Spec and Finish on the next screen.
- Hopefully everything goes well.
Easier than pushing is checking out a project.
- From Eclipse, select File -> Import and select Projects from Git under Git.
- Select Clone and fill this form just like step 4 of the previous section.
- Select the branch you would like to check out.
- Select the location you would like to checkout to.
- You should be back to Import Projects from Git window with your newly cloned repo showing.
- Select your repository and follow the instructions (defaults should be fine).
After configuring eclipse, you should probably set a non-empty passphrase to your ssh key. It is not the scope of this post to discuss why you shouldn't leave your passphrase empty, but here is how:
$ cd ~/.sshThis command will prompt for a new passphrase and you are done!
$ ssh-keygen -f id_rsa -p
Hope this was helpful. Feel free to comment or add any info.
[1] http://help.github.com/linux-key-setup/
[2] http://help.github.com/troubleshooting-ssh/
[3] http://blog.doityourselfandroid.com/2010/08/14/git-github-and-egit-eclipse-integration/
[4] http://www.eclipse.org/egit/
Cheers,
Lucas Piva
Thanks for a great tutorial, got me up and running in no time.
ReplyDeleteThanks for your helpful tutorial. May I know why Eclipse + EGit don't accept passphrase during remote->push? is it a bug?
ReplyDelete