Visual Studio Online, Git, and Eclipse

This post will show how easy it is to use a local Git repository with Eclipse for source control, and how to push to Visual Studio Online.

Background

Working on a few demos with Eclipse, and I am a bit of a code packrat.  As I build stuff, I post it to my blog, but I also try to check it into Visual Studio Online to make it easy on myself to run the demo at some later time.  I haven’t worked with Java and Visual Studio Online, so I wanted to see what the experience would be like.

The really nice thing about Visual Studio Online as a remote Git repo is that you get FREE UNLIMITED PRIVATE REPOS.  You get 5 free basic user licenses, free work item tracking, and a whole lot more

Eclipse and Git

This is ridiculously simple.  I downloaded Eclipse Luna, which already has Git integrated with it.  The environment that I created is documented thoroughly in the post Creating an Eclipse Development Environment for Azure.  I then installed the latest Git for Windows installation in order to have Git Bash support. 

To make things simple, I choose New / Maven Project.  I accept the defaults on the first screen, and then go to archetype selection where I choose the Quickstart archetype.

image

On the next screen, I provide a group ID, artifact ID, and version, then click Finish.

image

I then run the project and confirm that I see “Hello World!” in the console pane.

image

OK, enough coding, let’s check into source control.  Right-click the project and choose Team / Share Project…

image

Use Git as the repository type:

image

On the next screen, click the Create button to create a local repository, using the path for an existing folder.

image

Click Finish, Finish, and the repository is created for you.  The project is also moved to a folder within the folder location you specified.

image

The files have not yet been added, they are just untracked files at this point.  I can run Git Bash, change directory to the path, and run “git status” to see that the files are untracked.

image

Right-click the project in Eclipse and choose Team / Commit:

image

Provide a commit message:

image

Click Commit and the files are staged and committed.  We can then confirm this in Git Bash using “git status” and see that the working directory is now clean.

image

Push to Visual Studio Online

Now that you’ve committed to a local repository, it’s really simple to push to Visual Studio Online. First, we need to make sure that you’ve set up alternate credentials.  Go to your Visual Studio Online account and click on your name, then select My Profile.

image

Go to the Credentials tab and add a secondary user name and password.

SNAGHTML1151a7

Next, go to the New link to create a new project.  Choose a process template, and use Git for version control.

image

Click Create Project and the project is created for you.  Once created, go to the Code tab.  You’ll see instructions on pushing an existing repository.

image

I then copy the commands and enter them into Git Bash, where I am prompted for my username and password.

image

Once that’s complete, I head back over to Visual Studio Online and refresh the page.  Let’s go view the source of app.java and see that it’s pretty-printed for us.

image

We can now manage our repository locally and push to the remote Git repository, our source is stored in Visual Studio Online. 

What would be nice is if we had all the work item and even build integration.  That’s the next post, using the Team Explorer Everywhere plugin with Eclipse to enable Maven builds on Visual Studio Online, with no infrastructure setup required. 

For More Information

What is Visual Studio Online? – Details the features of the service

Creating an Eclipse Development Environment for Azure

Maven Builds in Visual Studio Online