Alex headshot

AlBlue’s Blog

Macs, Modularity and More

Setting up Google Code with Git

2011, eclipse, git, google, gtotw, tip

Since Google Code has started to support Git, I wanted to take the opportunity to reboot the ObjectivEClipse project to consume the Eclipse CDT mirror on GitHub so that I could keep up to date with the main mirror whilst adding support for Objective-C. This post shows you how you can migrate your existing Google Code repositories to Git.

Firstly, you’ll need your account details from https://code.google.com/hosting/settings. Since Google Code uses https instead of ssh for its code pushes, we need to know what the password is to use.

For security reasons, I recommend against using your Google Account password. Although it’s possible to configure, in essence the password is transmitted in plain text, albeit over an https connection. But if this password gets out, you’ve lost control to all of your Google Account estate.

Instead, Google Code shows you your GoogleCode password when you visit the URL above:

alex.blewitt@example.com’s googlecode.com password: Tm90TXlQVyEK

We can use this password to authenticate instead, and if it gets let out accidentally, like Doctor Who, we can click on the “Regenerate” button and get a new one.

Ordinarily, we wouldn’t want to have to remember this each time we use clients. You might be using a GUI tool (like EGit*) which remembers the password for you, but if you want to do things on the command line then using SSH keys to login are widely known but not applicable for https connections.

Instead, we can put the entries in the ~/.netrc file (on Unixes, at least) which will be used for the interop with the server. We can configure it like so:


echo machine code.google.com >> ~/.netrc
echo login alex.blewitt@example.com >> ~/.netrc
echo password Tm90TXlQVyEK >> ~/.netrc
chmod go= ~/.netrc

Note that this applies only to machine connections going to code.google.com, but you might want to configure it for your project’s name directly:


echo machine project.googlecode.com >> ~/.netrc
echo login alex.blewitt@example.com >> ~/.netrc
echo password Tm90TXlQVyEK >> ~/.netrc
echo machine wiki.project.googlecode.com >> ~/.netrc
echo login alex.blewitt@example.com >> ~/.netrc
echo password Tm90TXlQVyEK >> ~/.netrc

Note that the project’s wiki is in a different location than the main code for Git and Hg repositories (in SVN, it’s part of the same repository as the code).

As an alternative, you can access using the code.google.com host for both the project and the wiki – just suffix the project name with .wiki instead, e.g. for https://code.google.com/p/objectiveclipse/ use https://code.google.com/p/objectiveclipse.wiki/

Note that when you convert your project over from SVN to Git, it will appear that the Wiki content gets deleted. That’s because the Wiki server starts serving content from your new Wiki location, which won’t be populated with the old content.

Fortunately, migrating the wiki content is easy enough. You can access it via the old SVN site you have, which though it’s not visible via the main project’s URL, is visible via the direct project repository site:


$ git clone https://wiki.project.googlecode.com/git projectWiki
$ svn checkout http://project.googlecode.com/svn/wiki wiki
$ cp wiki/*.wiki projectWiki
$ cd projectWiki
$ git add .
$ git commit -a -m "Imported from old SVN wiki"
$ git push

You now have your wiki pushed to the repository. Of course, if you wanted to maintain history, then you could instead do a git svn clone instead.

Migrating the main repository (from GitHub to GoogleCode) should be as simple as adding a new remote, and hitting push:


$ cd /path/to/existing/github/clone
$ git remote add googlecode https://project.googlecode.com/git
$ git push googlecode master:master

Congratulations, you are now using Google Code in conjunction with Git.

* Note to EGit users: there’s currently a bug which prevents EGit from using Google Code since the latter reports an invalid value.