Saturday 5 November 2011

Working with a Codespaces.com Git repository on Windows–Pushing your code remotely

This post is the second part of a mini series which I have written to aid in setting up and using your Codespaces.com Git repository remotely on Windows.

  1. Getting started; setting up your SSH Public Key
  2. Pushing your code into the hosted repository (this article)
  3. Pulling your code from the hosted repository

Pushing to your remote repository

The first step to pushing your code into a remote repository is to create one in your Codespaces.com Admin section. You will find a settings area where you administer your users, projects, repositories and backups.

Once here click on the ribbon button to create a new Git repository.

image

A dialog will appear asking for information about the new Git repository. Fill in all the details which the required taking note of the name of the repository as this will be required later.

image

I’m using a code project which was originally posted on Github for some example code to post.

Once the information has been filled in click “Save” and your new repository should appear in the list on the right hand side. If this doesn’t automatically appear then select the “Git Repositories” option from the “Settings” tree view on the left and it will refresh the list and should now appear.

image

If there is a notification of failure or you are unable to see the repository in the list then try again. If this continues to be unsuccessful then contact Codespaces.com support.

If you now navigate to the “Source Code” tab and select the newly created repository from the dropdown you will see that it has been created but there are no folders in it yet. It will display a folder called “Empty Repository” however this is not a real folder and will disappear once you have submitted some code to it.

The repository has been created and you will be given a url on which you can access it by. It will be in the format of:

git@codespaces.com:username/repositoryname

Please replace username and repositoryname as required with your specified credentials. These can be found next to the branches dropdown list on the “Source Code” tab.

Getting Git Working

The next step is to get Git, which has been installed on your computer, talking to the remote repository we’ve just created and to push the code into it.

Find the folder where your code is. This will be where you already have an established local repository where you have been committing changes to for a while. Right click on this folder and click “Git GUI here”. This will fire up the Git GUI at this location.

At this point Git locally doesn’t know about the remote location so we need to add the information into the system. Click the “remote” option in the tool bar and “Add …”.

image

Fill in the required fields making use of the url which was created earlier when initialising the repository. Select the “Do Nothing Else Now” option as we will perform the Push in a minute.

Once you are happy with the information click “Add”. Now go back to the Git GUI and re-select the “remote” option in the tool bar. You will be presented with more options now a remote connection has been setup.

image

In the main window click “Push” from the list of action buttons which appear towards the bottom of the screen. In the dialog which appears select the correct remote destination repository. This dropdown will only have the remote location you just entered unless an additional location had already been setup.

image

There are a number of options here which you can select. You may need to Force the overwrite of the existing branch if you are working with an old branch you want to re-use or if something has gone wrong earlier. Finally click “Push”.

A new dialog will appear and it will inform you that it is pushing the code to the repository and sit there for a few seconds.

image

At this point it another window will prompt you for your passphrase you created in the first part of the series and click ok.

If everything went well you will get a big green success bar displayed.

image

Now to check that it worked we want to check the remote repository. Navigate back to the “Source Code” tab in your Codespaces.com dashboard and refresh your repository listing.

image

You will find that the “Empty Repository” folder which was there earlier has now disappeared and been replaced with your committed code. You can now browse the code online through this web application view.

Conclusion

In this post we have created our remote Git repository in our Codespaces.com account and pushed up the content of our local Git repository using the Git GUI.

Next time we’ll be pulling the remote repository code down onto our development system in a brand new local repository to replicate hard drive failure or a multi development machine environment.

No comments: