So we have a new project in IntelliJ with the starter layout provided by the Spring Initializer and we have an empty git repository in VSTS. We now have to link the two of these together so that all your future code changes have a place to live.
First we need to tell IntelliJ that this is a git repository. The easy way to do this is use the VCS menu.
Yes there is an option to ‘Import into Team Services Git’ and you would probably think that this would be the best option to select but it will only work if there is no repository on the VSTS side but as this is a new project on VSTS there is already a repository there (It would be nice if the VSTS Tool could detect that it is a blank repository and allow it to be linked).
Once you have told IntelliJ that this is a git repository you will need to add the existing files to the repository and then commit them.
Right click on the top level of the project, find the ‘Git’ menu and then select ‘Add’ to add all the existing files in the project to the repository.
Then click on the ‘VCS’ menu and select ‘Commit Changes’.
The commit changes dialog box will appear, just go ahead and commit everything.
At this stage we still have not linked the local Git repository and VSTS. To do this we need to use the terminal but before we do that lets have a quick look at the main project screen in VSTS as that will give us the commands we need to use…
You can see the exact commands that we will need. Also you may need to generate Git credentials if this is the first time you have tried to have git and VSTS talk from your machine.
To make things even easier you don;t need to open a separate terminal application. IntelliJ gives you a terminal window by clicking on the terminal option in the bottom toolbar. It opens the terminal in the correct directory so you just have to copy and paste those two commands from VSTS to the terminal tab
and now if you return back to VSTS and click on the Code tab you will see your source controlled git repository.
One thing to note is that a single VSTS project supports having multiple repositories. If you want to add a second repository to a project you can get IntelliJ to do the work by selecting the ‘Import into Team Services GIT’ option on the menu in the first screenshot above, selecting the project and giving the repository a name.
We are now ready to start writing code…