Connecting Team City to Visual Studio Online using Git source control

I was on a client project that was using Team City for their builds. I migrated their source control from SVN to using Visual Studio Online (as they had less than 5 users it was free). But I had issues trying to find any documentation on how to successfully connect Team City to Visual Studio when you are using Git for the source control. Hopefully these steps will help someone else in the future.

Where I was going wrong was trying to treat it like it was a TFS project, instead I should have been treating it like a standard Git repository.

For this blog post I am using the TFS team project I created during a live demo I gave for the Windows Azure web camp.

Step 1: Enable alternate authentication credentials

You will need to tell Visual Studio Online to enable other tools (such as command line Git tools & Team City) to be able to log in using a username & password.

  • Load your team portal, then in the top right click “My Profile”.
  • Go to the credentials tab and click “Enable alternate credentials”

image

image

Step 2: Obtain the URL for your Git repository

The easiest way I’ve found to get the URL for your git repository is to open a Git command prompt and list the remote origin

  • In Visual Studio go to the changes section in the Team Explorer tab.
  • Click “Actions” and select “Open Command Prompt”
  • In the command prompt type
    git remote show origin

image

image

 

Step 3: Enter details into Team City

This is the part that confused me, as I kept trying to connect with the TFS plugin. The secret is to just treat it as a Git repository.

  • In your team city project, click to add a “New VCS Root”
  • Type of VCS: Leave as <guess from repository URL>
  • Repository URL: Enter the Git repository URL obtained from the command prompt (in this example it would have been https://ausazurewebcamp.visualstudio.com/defaultcollection/_git/MelbourneSoftdrink
  • Username: Enter your Visual Studio Online username
  • Password: Enter the password you created when enabling Alternate Credentials.

 

Once it has connected you should be able to just click “Auto-Detect build steps” and have Team City download your source code, and automatically find your .sln file.

image

Advertisements

Using the GitHub for Windows app with BitBucket

If you aren’t using any form of source control in your project then stop right now and fix this. To get up and running with Git takes a whole 10 minutes to set up, and you will have your source code up in the cloud, should your computer blow up in the future (or you absent mindedly delete an important file).

Last year I wrote a blog post explaining how you could get free online source control for your personal projects by using a combination of a free account at http://bitbucket.org/ and the GREAT Git client created by GitHub http://windows.github.com/. Things have progressed so it is time to write an update.

BitBucket vs. GitHub

Lets take a quick look at a matrix that explains the two servies. GitHub is quickly becoming the De facto place to host public open source projects. However if you are working on your own project you will probably want to keep your code private. This is where BitBucket shines, if you just want to a place to host all of your private repositories, then you can have unlimited private ones. The limitation of 5 collaborators is fine for private projects.

BitBucket GitHub
Private repositories Free
(Limited to 5 collaborators)
PAID
Public repositories Free Free

The GitHub for windows application

Using Git from the command line can be hard. There are a lot of commands to learn while simultaneously trying to learn the workflow of Git works. While it is important long term to understand these commands, when getting started a GUI can help ease you into this new world.

image

The GitHub for Windows application has great integrated support for BitBucket (as can be expected), however it can work as a generic Git client just fine. This will allow us to use it with BitBucket.

Creating a repository on BitBucket

The new sign in screen on BitBucket.org surprised me. You can now actually sign into BitBucket with your GitHub account *Mind Blown*

image

Once you have logged in, create a new repository

image

Connecting the GitHub app with BitBucket

Once you have created a repository, find a place where it displays the address of your new Git repository (e.g. under Get Started). Then select the URL and then drag the text from your browser, and drop it into the GitHub for Windows app. It will automatically add the repository.

image

Now place your source code within that folder in Windows Explorer, commit your source code into the repository, then publish your new change set back up into Bitbucket. Done easy!

image

image

image

By David Burela

Online source control for your personal projects

Overview: This blog post covers how you can use “GitHub for Windows” with BitBucket to give you free online source control storage for your projects. Phil Haack recently blogged on how you can use GitHub for Windows with git repositories hosted elsewhere, I thought I would provide a step by step guide on how to do this with Bitbucket.

Many of us work on little side projects, it is what geeks do. But I am still surprised at the number of people that give me a blank look when I ask them what source control they are using on their personal projects. “We use TFS at work”, is the usual response, “but I don’t do anything with my own code. I just zip it up at now and then”.

Lets change this. It couldn’t be easier to get started!

Git is a great tool for doing source control locally, it supports change sets so that you can see how your code evolved over time. Unfortunately it can be difficult to get started with Git due to the number of command line tools and new concepts that need to be learnt. This is where GitHub for Windows comes in. It lets you easily create Git source code repositories and check your change sets in, via a nice visual interface.

To compliment this, there are 2 main websites that allow you to synchronise your local Git repositories with online cloud storage, meaning that your source code is safe from your computer blowing up, and also allows you to work across multiple PCs (or team mates).

  1. https://GitHub.com/ – Free for public repositories, but you pay for private repositories
  2. https://Bitbucket.org/ – Free unlimited private repositories, but you pay to add more than 3 team members

Personally, I use GitHub for anything that I share with other people (code samples, tutorials, etc.) and I use Bitbucket for my own personal projects. I previously blogged about my use of Github https://davidburela.wordpress.com/2012/04/17/developer-blog-banter-3-responsecommunity-coding/

Connecting Bitbucket with GitHub for Windows

It is really easy to connect and start backing up your projects to Bitbucket.

  1. Install GitHub for windows http://windows.github.com/
  2. Sign up for a free account at https://bitbucket.org/
  3. From Bitbucket, select Repositories –> Create new repository.
  4. Create a new Git repository
    image
  5. Once created, you will be taken to the repository’s home page. Copy the repository url
    image
  6. From the start menu, open the Git Shell and paste in the git command that was copied in the previous step. This will create a new folder, create a new git repository inside that folder, and link that repository with the online repository on Bitbucket.org. This means you’ll be able to keep the 2 in sync easily.
    image
  7. Open GitHub for Windows.
  8. To let GitHub for Windows know about the repository, simply drag the folder from windows explorer onto the application window. This will allow you to commit change sets and synchronise with the online repository.
  9. Start adding files to the folder (or create a new Visual Studio project inside that folder), then commit change sets periodically.
    image
  10. Once you have committed a number of change sets to your local git source repository, push the change sets up to your Bitbucket account by clicking the publish button.
    image
  11. If you browse to your repositories home page, you will see all of the change sets synchronised.
    image
  12. To retrieve the source code from another machine, simply repeat the first few steps to install GitHub for Windows, open a Git shell to run the initial command and drag the folder into the Github for windows app to start committing and publishing change sets.

Summary

With free tools and online storage, there are NO reasons for you to not use some form of source control to keep your projects safe. Start using it on one of your projects now and save your code from a lost hard drive!

If you want to start learning advanced git concepts, then here are some resources to help you get started

By David Burela

Developer blog banter #3 Response–Community coding

This is my response to https://davidburela.wordpress.com/2012/04/17/developer-blog-banter-3-show-tell/
Share a single interesting thing you’ve worked with recently. A tool, framework or technology for example.

The coolest thing that I’ve used recently has got to be the combination of https://GitHub.com + Markpad
I had used GitHub frequently in the past as a consumer of data. To download OSS applications to use, or .Net frameworks to include in my projects.

However, recently a tweet caught my attention.

I realised that my usual workflow when writing a blog post was:

  • write the code examples in the post
  • create a working sample application
  • zip it all up
  • host the the .zip file somewhere for readers to download.

After that the code always went stale and I never updated it. David Fowler got me thinking “He is correct. I really should make it easier for others to pull down my source code. And at the same time make it easier to update for when I use the same code in user group presentations

I created my first few repositories https://github.com/DavidBurela and uploaded the source code for a Windows Phone 7 application and source code samples from presentations I gave. GitHub makes it really easy to get started and they have a heap of resources to get started.

With my repositories created and ready to share with the world, there was just one thing missing… a proper README file. When someone navigates to your repository, GitHub looks within the repository for a README file, if it finds one it renders and shows it. Its a great way to give people an introduction to what your repository is for. An example can be seen in my WP7 repository https://github.com/DavidBurela/Windows8DeveloperCampPhoneApplication

The README file is written in a format called MarkDown (as opposed to mark up languages). It can be difficult to write the README files without seeing rendered in real time. This is where MarkPad comes in. It is a MarkDown editor with real time previews.

These 2 products have made my life that much easier to share code with the community. It can be difficult configuring your system with Git for the first time. I have included some links below to help you get started. (But it has been rumoured that GitHub are creating GitHub For Windows, similar to their GitHub for mac client. Which should make things much easier in the future)

Links to get started with Git & GitHub

By David Burela