Code, Manage and Collaborate with Bitbucket and Visual Studio

This blog post is a quick demo on how to integrate Visual studio with an existing code repository on Bitbucket.

There are so many blogs that explain Git and Bitbucket in great detail. You may follow the below resources to get basic understanding of Git and how Bitbucket uses Git.

This post assumes that you have the following prerequisites:

  1. Bitbucket account with appropriate credentials. If you do not have one Sign Up Here
  2. Visual Studio 2013 or higher installed.

Let’s get started!

What is Git?

“Git is a free and open source distributed version control system designed to handle everything from small to very large projects with speed and efficiency.”

Once you install Git, you will be able to create a local repository, commit your changes locally and then push to the cloud or origin.

Installing Git is easy and this post will cover this for you.

What is Bitbucket?

Bitbucket is a cloud-based flavor of Git for professional teams.  This is how it works – when you add/modify files in your local computer, changes are committed to local repository (i.e. Git repository) and then synced Bitbucket. You will know more when you read through this blog post.

Git is the underlying engine that does all the heavy lifting and Bitbucket is just a wrapper that leverages Git.

Following are the key steps to integrate Visual Studio with Bitbucket.

 Step 1: Install Git. (Link to download)

Please follow the steps and install Git.

Git Install Step 1

Git Install Step 2

Git Install Step 3

Git Install Step 4

Git Install Step 5

Git Install Final Step

Step 2: Create Code Repository in Bitbucket.

Please follow the steps and create Bitbucket Repository.

Create Bitbucket Repository Step 1

Create Bitbucket Repository Step 3

Once the repository is created, navigate to the ‘Overview’ section within the repository.
Copy and save the highlighted URL, you will need this later.

You should see the following only if you are working with an existing repository.
If you followed this blog post and created a new repository you will not see the following.

Step 3: Use Visual Studio to create a local Git Repository.

a. Navigate to the ‘Team Explorer’ within visual studio.

  • Click ‘Clone’ option under Local Git Repositories.
  • Provide the URL that you saved in the previous steps in the first text field.
  • Give the path to the local folder where you want the Git repository to be created in the second text field.

Create Local Git Repository using Visual Studio Step 1











b. Enter the user name and password for the Bitbucket account.

Create Local Git Repository using Visual Studio Step 3

C. Check if the repository is created in the Visual Studio and local File System.

Visual Studio:

Create Local Git Repository using Visual Studio Step 2

Local File System:

A hidden folder ‘.git’ will be created (Check your ‘Folder Options’ to see ‘hidden Items’)
This indicates that the folder is being watched and tracked by Git.

Local Git Repsoitory

Step 4: Add a new project to the Git Repository.

Important!: When you create a new project, make sure you  are creating using ‘New’ under Git Repository.
Double click on the Git Repository name and you should see the following.
Create new project in the Git Repository

DO NOT create the project from the New option with in ‘File’ menu in the visual studio.
You can re-associate with the Git repository later, but this is the cleanest and the easiest way of doing it.

Give appropriate name to the project and make sure your project location matches the Git Repository location.
Create a new project in the local Git Repository

If you notice clearly, you will find a ‘Plus’ icon next to the files, indicating that it is under version control.
Visual Studio Project created in the local Git Repository

Step 5: Commit and sync the project to Bitbucket.

Right click on the Solution name and hit commit. Remember, this is only committing to local Git Repository!

Commit the newly created project

Give appropriate comments. You are still committing to local Git repository.

Add comments while committing the project

Hit ‘Sync’ . This will push the changes to the outgoing commits. You are still syncing to local Git repository.

Sync to Bitbucket or origin

Push the changes to Bitbucket using ‘Push’ option under Outgoing Commits. THIS PUSHES TO Bitbucket!

Outgoing commits to origin

Check if you can find the newly created project in the Bitbucket.

Code Uploaded to Bitbucket Repo

Congratulations on our first integration with Cloud Hosted Version Control Management System.

Happy Coding!