Click here to Skip to main content
15,867,594 members
Articles / DevOps / Git
Tip/Trick

Getting started with GIT, Visual Studio, and BitBucket

Rate me:
Please Sign up or sign in to vote.
4.68/5 (13 votes)
25 Apr 2015CPOL3 min read 116.9K   26   10
Getting started with GIT, Visual Studio, and BitBucket isn't difficult - but it can take a bit of working out. Here is a simple explanation of what to do to get a new project under source control.

Introduction

Source Control. Next to a good solid backup system, it's the best friend a developer can have! Well, if you ignore the IDE, of course.

But... it can be confusing to get set up, particularly if (like me) you don't have to do it often - so each time you try, you forgot what took you all day to work out last time...:sigh:...I know I do.

So here is a simple, step-by-step guide to getting it done.

Background

This assumes you are using Visual Studio 2013 Community Edition, and that you have the "Microsoft Git Provider" plug-in set up and selected ("Tools...Options", "Source Control...Plug-in Selection", "Current source control plug-in" to check and select if needed.) If you don't have the plug-in installed yet, go here: MSDN[^]  

This also assumes you have set up an account with BitBucket[^] and can log in and create repositories. If you haven't, do this first!

Getting Started

Create the Project and Local Repository

Open Visual Studio, and select "File... NewProject"

Select the project type as normal, give it an appropriate name and solution name, then tick the box "Create new Git Repository" before pressing "OK".

Open the "Solution Explorer" pane, and commit your project:

  • Right click the Solution name, and select "Commit..." from the context menu.
  • This will open the "Team Explorer" pane. Enter a commit message where it prompts you to do so. (Until you do, it won't enable the "Commit" button). "Initial creation" is a good idea!
  • Press the "Commit" button.

Create the Remote Repository

Sign in to your BitBucket account and use the top menu: "Create...Create repository".

The form that appears lets you set up the repository: you need a Name, a Description is a good idea, and the rest is up to you! :laugh:

Press the "Create Repository" button.

When the Repository is ready, click "I have an existing project". This will show you the PUSH command detail you need:

cd /path/to/my/repo
git remote add origin https://YOUR_NAME@bitbucket.org/YOUR_NAME/YOUR_REPOSITORY.git
git push -u origin --all # pushes up the repo and its refs for the first time
git push -u origin --tags # pushes up any tags

The bit you need is the URL - from the second line in this example:

https://YOUR_NAME@bitbucket.org/YOUR_NAME/YOUR_REPOSITORY.git

Copy that to the clipboard.

Back to Visual Studio

In the Team Explorer pane, use the top dropdown (Probably currently showing "Changes") to select "Unsynced Commits". This will bring up the page with "Publish to Remote Repository".

Paste the URL you copied from BitBucket where prompted: "Enter the URL of an empty GIT repo" and press "Publish". It won't take long - or it shouldn't with a new project, there isn't a lot there - when it's finished you are done.

Back to BitBucket to Check

Click the "Source" button on the left hand side and Presto! your project is in the Repository.

Important!

One thing that caught me out immediately after writing this, was that the default gitignore file is set to discard any files starting with "Backup" - so you should avoid calling your projects, classes, or any files with them anything started with "Backup" if you want them under Source Control. It's well worth the occasional check on your BitBucket Repository to check that all your files are included as there is no visual clue anywhere else that they aren't... :swearword: :swearword: :swearword:

One of the main reasons for having source control is to share code with associates. Please, remember the Cardinal Sin of Source Control and never commit code that doesn't compile! You will annoy people to the point of them forming a lynch mob... :laugh:

History

  • 2015-04-25 First version
  • 2015-04-26 Typos, and added "Backup" filename warning

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
CEO
Wales Wales
Born at an early age, he grew older. At the same time, his hair grew longer, and was tied up behind his head.
Has problems spelling the word "the".
Invented the portable cat-flap.
Currently, has not died yet. Or has he?

Comments and Discussions

 
QuestionIs visual studio community ed. 2017 ignoring .gitignore Pin
Member 122936975-Sep-17 1:09
Member 122936975-Sep-17 1:09 
QuestionWonderful Pin
MosuliNodangala1-Sep-17 23:48
MosuliNodangala1-Sep-17 23:48 
PraiseThanks a lot Pin
Majid Basirati26-Jun-16 3:26
Majid Basirati26-Jun-16 3:26 
GeneralRe: Thanks a lot Pin
OriginalGriff26-Jun-16 3:39
mveOriginalGriff26-Jun-16 3:39 
QuestionThanks for the warning! Pin
Programazing22-Nov-15 7:44
Programazing22-Nov-15 7:44 
AnswerRe: Thanks for the warning! Pin
OriginalGriff22-Nov-15 8:03
mveOriginalGriff22-Nov-15 8:03 
PraiseMany thanks Pin
Tom Ash27-Oct-15 11:08
Tom Ash27-Oct-15 11:08 
GeneralRe: Many thanks Pin
OriginalGriff27-Oct-15 11:21
mveOriginalGriff27-Oct-15 11:21 
QuestionGreat! Pin
PsylenceDave18-Sep-15 2:08
PsylenceDave18-Sep-15 2:08 
GeneralThanks! Pin
olafdonk17-Jun-15 22:34
olafdonk17-Jun-15 22:34 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.