Importing Java code into Git on Visual Studio Online from Eclipse

Last time I wrote about Creating a Build.vNext agent on Linux. I ended that post with the idea to build a Java application on Linux. The first thing that we’ll need is some Java code in VSO to build. Being a Java newbie, it took me quite a bit of figuring out on how to do that. I thought I’d share my experiences here, for you to enjoy.

Install Eclipse and Team Explorer Everywhere

The first thing you’ll need to do when working with Java is installing a Java IDE. You can download it from here. I chose to download the “Eclipse IDE for Java EE Developers”, since that already includes some things that are usefull later (like Maven integration). Installation is as simple as unzipping the files to a folder of your choice. However, I did have a strange issue when using the default Windows unzipper, resulting in Eclipse not starting up. When using 7-Zip, all is fine. Once you get Eclipse running, you’ll see a nice empty interface.

imageNext we’ll install Team Explorer Everywhere.  Go to “Help”, “Install New Software…”

imageThen click the “Add” button to add a repository.

imageEnter the details for the Microsoft Eclipse repository and click OK.

image   Next, make sure the Microsoft repository is selected, check the TFS plug-in and click Next.

imageAfter finishing the wizard the TFS plug-in will be installed and you’ll need to restart Eclipse. You can open the plug-in by clicking “Window”, “Show View”, “Team Explorer”.

imageFinally, click “Connect to Team Foundation Server” and select your VSO account and project.

image Voilà, you are connected to VSO from Eclipse!


Upload code into repository

Before we can build something, we’ll need something to build, obviously. I’ve put a demo application on my GitHub, which you can download here. Unzip the file and put the “Demo/hellomaven” folder somewhere on your hard drive. In my case, I used “D:\Demo”.

image In my VSO project, I have created an empty Git repository to hold the code. We can use Eclipse to push the code there. First, we’ll need to clone the repository. In Eclipse, go to Team Explorer and click “Git Repositories”. Then right-click your repository and click “Import repository”.

imageIn the wizard, select your repository and click “Next”.

imageOn the next page, select a local folder where you want to clone the repository. A subfolder with the name of your repository will automatically be created. Don’t forget to provide your credentials. If the account you used to log-in to Windows is something different than what you’re using for VSO, you’ll need to provide your alternate credentials here.

image Since there is nothing in the repository yet, we can’t select an initial branch…

imageNext, the wizard will ask if you want to import or create Eclipse projects from this repository. Since I’ll import my demo project into this repository later, I’ll select “Import detected Eclipse projects”.

image Since the Git repository is empty, there will be no projects to import. That’s OK, we’ll add a project later. Click “Finish” to start cloning the repository. It’ll appear as if nothing happens, but you will get a (empty) copy of the repository on your local disk.

imageNow we can import our code! First, we’ll open the project in Eclipse. To do that, right-click in the Package Explorer (“Window”, “Show View”, “Package Explorer” if it’s not visible) and select “Import…”.

imageSelect “Existing Projects into Workspace” and click “Next”.

image   Browse to the directory where you unzipped the demo project (or your own code of course), make sure your project is checked and click “Finish”.

imageThis will import your project into your workspace and make it visible in the “Package Explorer” window. From there, we can move it into our Git repository. Right-click the project and select “Team”, “Share project”.

image  Select “Git” as the repository type and click “Next”.

imageSelect your repository in the dropdown list, make sure your project is checked and click “Finish” to move the project into the Git repository.

imageNow all we need to do is commit and push our code to VSO. To do that, right click your project and choose “Team”, “Commit”.

imageType a meaningful commit message (you always do this, right?), select all files and click “Commit and Push” to start pushing everything to VSO.

image Since this is the first time we’re pushing, we’ll need to select a remote branch to push to. In this case, I’ll go with the default “master”.

imageFinally, click “Finish” to start the magic…

imageIf everything went smoothly, you’ll get a result window without any errors.

imageYou should also see your code in the “Code” tab of the VSO web interface.

imageSo that’s it! You now have your Java code in a Git repository, hosted on Visual Studio Online! You can now start using Git from Eclipse, where all the usual Git stuff (commit, branch, merge, history, rebase, etc) is available under the “Team” submenu in the “Package Explorer”.

imageYou can also use the “Git Staging” view, which will give you a nice and easy way to select the files that you want to commit. Just drag files from “Unstaged Changes” to “Staged Changes” to include them in your commit.


Hopefull this will get you up and running with Eclipse, Git and VSO quickly! My next post will be about using VSO Build.vNext to actually build the code.

Happy Gitting!        


7 thoughts on “Importing Java code into Git on Visual Studio Online from Eclipse

  1. Mario Majčica says:

    Hi Kees,

    did it happened to you to try TFS 2015 Update 1 and Git and TFVC in the same project? If I add a Git repository to a project that was created with TFVC, my Git repos are not listed by this plugin.
    Are you aware of any workaround about it?



Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your 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