Using Source Control with BitBucket, Source Tree and Visual Studio – Part 1

Source Control is a concept that I had overlooked for several years. As the sole developer for several companies over the years I did not see the need for source control mainly because I did not understand source control. Source control ultimately is a way to protect you from your own mistakes and the mistakes of others. By using source control you can have a way to easily go back to previous versions of your code if you made some changes to an area by mistake or if the client decided that they did not like the new changes and wanted the old ones back. All of these situations have happened to me. Had I been using source control these would not have been the major issue that they turned into.

BitBucket is a website that is run by Atlassian and offer free private repositories. These repositories can be easily accessed and controlled with Atlassians GUI git client called Source Tree. The following describes how to install git, source tree and create a BitBucket account as well as how to set up your first branch and create a Visual Studio project to work with source control.

Account Setup

Install Git

  • In a web browser open up www.git-scm.com
  • Click the “Downloads for Windows” button
  • After downloading, install Git using all of the preselected defaults

Installing Source Tree

  • In a web browser open up www.sourcetreeapp.com
  • Click the “Download SourceTree Free” button
  • After downloading, install SourceTree using all of the preselected defaults

Create Bit Bucket Account

  • In a web browser open up www.bitbucket.org
  • Enter your information into the sign up form on the front page and click “Sign up for free”
  • Enter all your information and follow all sign up instructions
  • At the “Create Your First Repository” screen click No Thanks

Repository Creation

Creating a Repository on BitBucket and Cloning in SourceTree

  • Open and sign in to www.bitbucket.org if you are not already there
  • At the top click on the “Repository” menu option and select “Create repository”
    • Enter a new name for your repository (This will be your solution name in Visual Studio)
    • Enter a description if desired
    • Leave the Access Level checked to make this a private repository
    • Leave Repository Type set to Git
    • Click the “Create respository” button
  • On the next screen click the Clone link on the left hand menu
  • Click the Clone in SourceTree button
  • The SourceTree application will open with a URL Actions dialog box
  • IMPORTANT: Click the ellipse button […] to the right of the Destination Path input box
  • In the “Select Destination Path” dialog box navigate to the following location
    • C:\Users\[username]\Documents\Visual Studio 2012\Projects
    • Create a new folder in this dialog box naming it the same as your repository name
    • Double click the new folder and click the Select Folder button
  • Back on the URL Actions dialog box click the Clone button

Creating a New Solution in Visual Studio

  • Open Visual Studio
  • Create a New Project from the start screen or File > New > Project
  • Select the Project type that you are going to create
  • In the Name box change the default name to the name of the repository you created in bitbucket
  • Click the Browse button to the right of the Location box
  • Navigate to and double click on the folder you created when you cloned the repository
    • C:\Users\[username]\Documents\Visual Studio 2012\Projects\[repositoryname]\
  • Leave the checkbox for “Create directory for solution” checked
  • Click the OK button.

Initial Project Commit and Push to BitBucket

Commiting Changes in SourceTree

  • In SourceTree double click on your newly created project on the left
  • Check the box next to Unstaged files
  • All the files should transfer to the above pane as Staged files
  • Click the Commit button on the top bar
  • In the text area that will eventually appear at the bottom of SourceTree enter the commit message of “Initial Commit”
  • Click the commit button

Pushing Changes to BitBucket

  • In SourceTree click the Push button on the top menu
  • On the new dialog box click the master check box
  • Click OK
  • Click the “Show Full Output” check box to see the Completed successfully message (this will also show you any error messages. NOTE: If you don’t when the push is complete, if successful, the box simply goes away.
  • When completed click the close button

Using Source Control – Part 1 (PDF)

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