Visual Studio Online provides two ways to do Source Control, either via Team Foundation or Git methodology. TFS provides a Centralized Version Control System (CVS) while Git provides a Distributed Version Control System (DVCS). A DVCS like git, gives you all the functionality of a CVS, but locally. This makes working offline a bit easier to manage and you can later sync your changes to the server.
Creating a Git Team Project in Visual Studio Online is the same way you’d normally create a team project. Click New… and in the window that appears, the drop down for Version Control, choose Git.
When you load connect to the Team Project in Visual Studio, if you don’t have the Git Extensions, you’ll be prompted to download two separate ones which each require a Visual Studio restart. Just click the links to start the download from the prompts that appear.
Once all the extensions are done and you’re connected again, you must clone the repository to your local machine.
Which you’ll then choose where to clone it to
Since there’s nothing in the Team Project, it’s time to create something. I created an F# project as I want to continue learning F# while using Git. I also used the code from my last blog.
Now that I have made some changes, I can commit them locally via the Changes button in the Team Explorer Home.
When you commit, an alert displays telling that the commit has been created locally and that in order to upload the changes to the server you have to do a Sync.
Clicking on Sync will bring you to the Unsynced Commits page.
To send your changes to the server, click Push. I did a push instead of a sync because there’s currently nothing residing in the repo.
Now normally when creating coding in Git, you create your own branch to work in then merge the changes to the master branch when your ready. Branches that you create can be shared between team members and before being fully merged into the Master branch can be reviewed by a Code Reviewer. I’m going to create a new branch, make some changes, then merge them into the Master branch.
The branch you just created is now the branch your coding in
Now I’m going to make some changes to the project and commit to my local ‘Phils’ branch
And again the commit alert
Problem is – it doesn’t show I can push my changes.
So I must first publish the branch I created.
Now I can Sync my changes to my branch.
I can now switch between branches and see the difference between the two.
My master branch:
And my Phils branch:
A quick switch just by hitting the drop down
Now, if I want my changes to be reflected in the main branch, I must execute a merge.
And an alert appears saying that a commit has been made
If I go back and check my current master branch, it will have my changes in it
But I still have to sync the changes to the source version.
Hit sync and boom.
Everything is copacetic.