[Basic for Absolute Beginner] – [Part 6] – Source Control
Imagine you have just finished some component of your app. You keep going and build something else, then hit Run. And suddenly everything throws errors, bugs show up everywhere, you delete the code you just added but the errors are still there, and it feels like you’re missing something?
Imagine further that your Team is working on some project, but each member is in a different place and you have no way to meet. How do you work together on one project?
All those questions, and many more, are answered by a Visual Studio feature called “Team Foundation Server”

The earlier parts:
[Basic for Absolute Beginner] – [Part 1] – Layout with XAML 1
[Basic for Absolute Beginner] – [Part 2] – Layout with XAML 2
[Basic for Absolute Beginner] – [Part 3] – App’s Structure and how to customize it
[Basic for Absolute Beginner] – [Part 4] – Basic Steps for a new app
[Basic for Absolute Beginner] – [Part 5] – Analytics for your apps
[Basic for Absolute Beginner] - [Part 6] - Source Control
The concept
Source Control is a way to manage your source code. Managing means you can look at versions, store them, restore them, share them, and so on and so forth. When you code something wrong, you can restore the previous code. You can create a new project from existing source, you can let a new member download the whole source code to work with you on a project, and that person can also view, delete, save versions and so on for their own code. At the most basic level, this blog post shows you how to use Team Foundation Server to version your source code
Registering an account
Microsoft’s Team Foundation Server, which has now been renamed Visual Studio Online, is a free service. You can create as many Projects as you like, but across all Projects you only get up to 5 free members. So when you register a Visual Studio Online (VSO) account, you get unlimited storage (that’s right, unlimited), at most 5 members, unlimited projects, and many other tools that require deeper knowledge to use http://www.visualstudio.com/ Go to that page and hit the purple Get Started for Free button

You are taken to a page; sign in there with a Microsoft account

Fill in a bit more of the required information, or answer whatever questions it asks

Once signed in, you can create your first Project
On the Service
Creating a Project

Hit the New button to create a new Project

Fill in the required information and hit the Create Project button. Once it’s created, hit Navigate to Project to go to your Project management page. That page holds a lot of information; for now you only need to care about the Member section

This shows every member in your project. Hit the Manage… button to add or remove members
Managing members
Within one Project

Each person’s name has a Remove button. Click it to delete a member. Hit Add to add a new one. Members are required to use a Microsoft account to use this service
Across all Projects
On the first page, click the Users button to see the list of all members in your account

Right now there are several account types: VS Ultimate with MSDN is the account for Microsoft Student Partners, and Early Adopter is the free account, which will later be renamed Basic

If you are an MSP, you can use your MSDN Subscription to register for VSO. You can add unlimited VS Ultimate with MSDN accounts. But you can only add up to 5 Basic accounts. The picture below shows this

That’s it. Now let’s open Visual Studio and set things up
In Visual Studio
Connecting to your account
Pick Menu > Team > Connect to Team Foundation Server. Sign in with the same Microsoft account you used to create the Online account

The Server has the form: https://nickname.visualstudio.com After signing in, every Project available on the Server is listed. Tick the Projects you want to connect to (the projects you are working on) and hit Connect
Adding the Project to Source Control
Open your Solution

Once it’s open, right click the Solution > Add Solution to Source Control…, and you’ll be asked which service to use.

Git is a free service, and harder to use than Team Foundation. A panel shows up; pick the Project you just created on the Web and hit OK

The adding happens quietly. You might feel Visual Studio freeze for 2-3 seconds. After that, each file in the Solution has a + icon in front of it

At this point your Project is managed by Team Foundation Server Source Control. However, this is still only a “change”. You have to Check in for these changes to be saved. Right click the Solution > Check In…

In the Comment box, type the note for this check in

The Included Changes (number) section lists the files in the Solution that changed and will be saved to Source Control in this check in. Once you’ve reviewed all the details, hit Check in

After a successful check in, a small notification shows up with the changeset number. You’ll need that number to restore later

Back in the Solution Explorer, you’ll see a lock icon in front of each file, meaning that file hasn’t changed since the last check in

Editing and Checking in
When you start editing some file, the lock icon changes

To save this change into Source Control, right click it and pick Check in. Note that when you change many files in a Project, you can pick the whole Project to check in. If you changed things across several Projects, you can pick the whole Solution to check in. Usually picking the whole Solution guarantees you don’t “Check in” less than you meant to. Team Foundation automatically finds the files you changed
Get Latest Version – Get Specific Version – Undo Pending Change
If you work on a project with many members and the others finish their code and Check it in to the Server, you have to pull the newest code down. Right click the part you want to update > Get Latest Version (Recursive)

- Recursive means exactly that. Every file inside it gets updated too
When you use this command and some of your files have changes not yet checked in, then if Team Foundation thinks it can handle it, it handles it for you by merging those changes together. However, if there are conflicting changes, you get the option to review the conflicts and decide
Get Specific version is another way to bring a Project or some file back to exactly the state of a particular check in. You can use the Changeset number, or a date, to search through all the check ins and decide what to “restore”
Undo Pending Change discards all your changes and brings the Project or file back to the most recent Check in.
So you now hold a magical time machine to control your Source Code, and to collaborate as a Team effectively