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.
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!
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:
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:
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.
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:
- 2015-04-25 First version
- 2015-04-26 Typos, and added "Backup" filename warning