Using Git with Visual Studio Online

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.

11192014_GitTeamProject

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.

11162014_ConnectedToGitProject

Which you’ll then choose where to clone it to

11162014_CloningRepository

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.

11192014_GitNewProject

Now that I have made some changes, I can commit them locally via the Changes button in the Team Explorer Home.

11192014_FirstCommit

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.

11192014_CommitAlert

Clicking on Sync will bring you to the Unsynced Commits page.

11192014_Sync

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.

11192014_Branch

11192014_BranchCreation

The branch you just created is now the branch your coding in

11192014_TargetBranch

Now I’m going to make some changes to the project and commit to my local ‘Phils’ branch

11192014_CommitToCreatedBranch

And again the commit alert

11192014_CommitToCreatedBranch_CommitAlert

Problem is – it doesn’t show I can push my changes.

11192014_BranchNotPublished

So I must first publish the branch I created.

11192014_PublishBranch

11192014_BranchPublished

Now I can Sync my changes to my branch.

11192014_BranchSync

I can now switch between branches and see the difference between the two.

My master branch:

11192014_BranchMaster

And my Phils branch:

11192014_BranchPhils

A quick switch just by hitting the drop down

11192014_BranchSwitching

Now, if I want my changes to be reflected in the main branch, I must execute a merge.

11192014_BranchMerge

And an alert appears saying that a commit has been made

11192014_BranchMergeAlert

If I go back and check my current master branch,  it will have my changes in it

11192014_BranchMasterLocallyChanged

But I still have to sync the changes to the source version.

11192014_UnsyncedOutgoingCommit

Hit sync and boom.

11192014_BranchMasterSynced

Everything is copacetic.

2012-02-14-hold all this slinky

Advertisements

Leave a Reply

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

WordPress.com Logo

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