DVCS part 4: remote repositories using EGit, HgEclipse

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:

step-by-step-install-git-on-osx-ubuntu-and-windows
step-by-step-install-mercurial-on-osx-ubuntu-and-windows

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:

Please remember:

  • 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 git@github.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:

Now we have successfully pushed to a remote repository on OSX.

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:

  1. Verify that all PuTTY applications are directly in the Mercurial installation folder – so they are at the same level then “Mercurial.ini”
  2. Verify that Pageant is running
  3. 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.

4 responses

  1. Thank you very much for the post. I am also very new to Git and Github and your blog entry helped me a lot to create easily an account on github.

    However, as long as EGit is such buggy (EGit doesn’t remember the URI), I stick to Git on the command line.

  2. Ekke, rather than importing the repository using the file protocol in the first place (which appears to create a second local copy of the repository), it seems better just to import the projects (‘Existing Projects into Workspace’) directly from the repository location and then share them (‘Team > Share Project…’) to expose their Git nature. When I did it this way, the remote repository (to which I had already pushed the repository previously based on Github’s instructions) was already configured (and remembered) for push…

    • Kenn, thanks for the tip – I’ll try it. … good to know because I plan to blog about some usual workflows how to use DVCS.
      ekke

    • Kenn, just reread your comment….
      In the first place I used the file protocol, because in my scenario there’s not only the workspace and the remote repository,
      there’s also a local repository outside eclipse.
      reason:
      I’m using a Local repository (outside eclipse) as a repository where all my workspaces working on these projects can push/pull before pushing to the remote repository.
      I work at the same time in the same projects from OSX, Ubuntu (through Parallels VM), Windows XP (through Parallels VM), Windows 7 (through Parallels VM)
      I have to do this to test redView on all OS – and want to be able to develop directly from each OS in the projects. But I dont want to push them directly to the remote repository,
      all pushes go to the Local repository (outside the OSX Eclipse).
      Then I’m able to pull all into my OSX workspace projects (which is my main working horse), polish the code and decide what to push to the Remote Repository.
      I’ll describe this more in detail later.
      ekke

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

%d bloggers like this: