This blog is part of a DVCS – blogseries: part 1 – install Git and Mercurial together with EGit and HgEclipse, part 2 – initializing of and importing from local repositories, part 3 – team options and committing/pushing to local repositories.
This time we want to work with remote repositories using EGit and HgEclipse. Lars Vogel has already published an article about “Egit and GitHub“, but I don’t want to push a single Eclipse project – I want to push a Repository with more then one project.
This post will describe how to push a bunch of projects to existing Servers like GitHub, Bitbucket or SourceForge, where your Open Source Projects can be hosted. How to create your own Remote Server isn’t subject of this blog. (perhaps a later one 😉
configuration / installation of ssh, generating ssh key pairs
Before starting with Remote Repositories we should be sure that the needed things are installed. Accessing remote repositories you’ll need “ssh” in most cases. Installation and configuration wasn’t as easy as expected (for me not being an Unix commandline guru), so I’ve written an extra add-on post describing these steps in detail for OSX, Ubuntu and Windows:
→ add-on posting: step-by-step-ssh-on-osx-ubuntu-and-windows
BTW: in the meantime (as an add-on to part 1) I also added step-by-step instructions how to install Git and Mercurial:
This blog entry needs Git and Mercurial installed and also ssh together with generated keys. If you don’t have this, please read the other posts first to follow this one.
Pushing a multi-project repository
As you know from previous blogs at the moment it’s not possible using EGit or HgEclipse to select some projects in Eclipse and simply add them to a repository. In part 6 of this series I’ll describe some workflows how this can be done.
From part 2 of this blog series we ended with this scenario:
- From your Workspace (left)
- Add / Commit goes into the cloned repository inside your workspace (left)
- Push… moves your changes (left) to the Local repository (right)
- Pull… gets changes from the Local repository (right) merged into Workspace repository (left)
Now we want to push changes to a Remote Repository. Would be really cool if I could manage my repositories inside Eclipse: select a source and target repository and perhaps do a Push from the Local Repository to the Remote Repository. Seems this isn’t the task of on Eclipse Team Provider Plugin (discussion at hgeclipse).
For this example I’m using my Workspace repository from where I’ll push to a remote repository.
Pushing to remote Git Hosts
The easiest way pushing to a remote host is using GitHub.
If you don’t have an account at GitHub, create a new one and also create a Repository. The most important thing: you have to add your ssh public key.
Hint: If you plan to create more then one repositories at GitHub, then you have to add the key to your account and not to the repository !
How to create the key and get the public key is described here in detail.
Now it’s easy to push to GitHub. At first go to your GitHub repository you want to push to and get the URL for private read-write access (ssh):
Click on the Clipboard Icon to copy the URL into the Clipboard.
Then back into Eclipse, right-click on one of the projects: Team-Options… Push…
Select “Custom URL“, because your “Configured remote repository” points to the Local Repository and paste the “URI”
Unfortunately you have to enter this URI every time you want to push again to the remote repository – EGit doesn’t remember the URI 😦 (I created Bugzilla 303402)
Select “git+ssh” as protocol, user is “git“.
Hit “OK” and enter the Passphrase (Password):
While testing I had a problem and authentication fails – restarting Eclipse fixed that.
If you still have problems accessing GitHub, you can verify if your public key works:
Open Terminal Application and type “ssh email@example.com” – GitHub should answer with your name and the message that no shell access provided. If this happens all should work well.
Go through Push Dialogs and at the end you get the result:
You can verify this at GitHub:
So we have successfully pushed our changes to a remote repository.
This work was done from OSX. Let’s go to a new created Ubuntu (easy to do using Parallels 5 Desktop 🙂
Install Git, Mercurial, JDK, Eclipse, Updatesites EGit + HgEclipse, copy ssh key. (How to do this I talked in other parts of this series)
Now we have a fresh empty workspace and want to import the projects from our remote repository:
There’s a Wizard available: “Import… -> Git -> Git Repository” , Enter the same URI as above where we pushed to from OSX. Then a message will display the Fingerprint of the Public Key and as next asks you if the host (GitHub) should be added to the known hosts:
Hit “Yes” and enter the Password (Passphrase) – then Hit “OK”
now select the branch – we only have the “master”:
verify the destination location
select the projects…
…and you’re done. I also tested under Windows – works the same, but I had to change Eclipse SSH2 Preferences from username\ssh into username\.ssh as described here. (the dot was missing)
In part 6 of this series I’ll describe some more workflows how to work with local and remote repositories from daily development.
Pushing to remote Mercurial Hosts
Git has GitHub serving repositories and Mercurial has Bitbucket:
If working with Mercurial, it’s a good idea to create an account and also a Repository at Bitbucket. Then go to your Account and add your SSH public key:
You can copy/paste and Add key or – more comfortable – Upload the key. How to create the key and get the public key is described here in detail.
Bitbucket tells you how to access your repositories – you can use HTTPS or SSH – click on the one you need and copy the link to clipboard.
Now switch back to Eclipse – we’ll try to push to the remote repository at Bitbucket: Team-Options… Push to… opens a Wizard.
If you select HTTPS, then you have to use your Username and Password from your Bitbucket Account. The URL can be copied from clipboard.
If you select SSH, then the User is always “hg” – after pasting the URL, HgEclipse will put the required informations into the fields for you. HgEclipse remembers all Usernames and Passwords (see below “Mercurial repositories View“)
Next View will display the changesets to push:
As always using HgEclipse, you can take a look into the changesets, doubleclick on a single change and compare the differences. (don’t wonder – this screenshot is from another push while testing – normaly it would fit to the screenshot before 😉
Hit “Finish” and you’re done.
You can verify at Bitbucket:
Please take a look at the Mercurial Repositories View in Eclipse. There you’ll see records of all repositories we accessed – in this case the Local Repository and also the Remote Repository from Bitbucket through HTTP and SSH.
Double-clicking on an Entry shows the details:
You can also create a new Repository – Record (right-click in the View) – and if issue 10981 is fixed even init new Reposiitories.
Lets try to get it back (Import clone) from there using Ubuntu.
copy your URL from bitbucket – HgEclipse will fill out the other fields
If this is the first access to Bitbucket, you get an info about the RSA key fingerprint and an info that the host “bitbucket.org” was added to the list of known hosts.
Follow the Wizard, select the projects and all is done.
Hint: if you get an error “remote: acces denied (public key)”, then perhaps you forgot to add your keys to ssh-agent with command ssh-add (details see here)
Perhaps you ask “why the hell should I do all this SSH – stuff if I can access Bitbucket through HTTP ?” The main reason is the security: ssh is more secure (as the name tells you). Also if you import from Bitbucket using HTTP then you’ll find the path in yourRepository/hg/hgrc where everybody can read your password:
using SSH there’s no security problem, because no one has your private key and passphrase:
As last test let’s see how it works under Windows. You know from this post, that the installation / configuration of ssh wasn’t so easy under windows.
Before testing the first time:
- Verify that all PuTTY applications are directly in the Mercurial installation folder – so they are at the same level then “Mercurial.ini”
- Verify that Pageant is running
- Verify that your key (*.ppk) is added to Pageant
if not – HgEclipse will hang without a message !
If all is done it works as easy as on OSX or Ubuntu:
…was a hard work to make EGit and HgEclipse run on remote repositories using ssh on OSX, Ubuntu and Windows. I hope that my experiences will help others to start easier…
Hint: As I already told you I’m just starting using DVCS -please correct me and add comments if there are better ways to do this work. thanks.
The overview of this blog series can be found here: https://ekkescorner.wordpress.com/blog-series/git-mercurial/. The next part we will do some branching -one o the real powerful things using Git or Mercurial.