Visual Studio and Repositories 101

Hi

So in my previous post I gave you a brief intro about repositories and some basics on what you can do with it. If you haven’t done so already, catch up –

Introduction

Intro to Repositories

Let’s take a deeper dive into it and see how we can get our hands dirty.

First things first – install the client. I use Visual Studio Community to do my editing. What you need to know is the client is just the start. There are extensions, SDKs, etc. that expands the client capabilities and allows a much richer experience

To work with most of what you will see in this series, you need:

visual-studio-community-2015-780x445

Go through the above, download and install the software and open accounts.

afbdac1c762d4023610bbea81e90ccb1

Done? Great, let’s continue

GitHub

Start by creating a repository (look for the green button in the top right). Note the free account allows you to create only public repos, so be careful with what you place there. Make sure you check “Initialize this repository with a README” so we can open it quickly in VS

Now, click the “clone or download” and then on “Open in Visual Studio”. You then need to enter your credentials to connect VS to GitHub and you can clone the repo to your computer. Choose a location and you’re connected. You just created a local copy of the online version

gitclone

Next, we need to add a solution. This will give us the option to browse the files from within VS.

Now, we do it for practical reasons only. I’m sure there are other, far more efficient ways to accomplish the same goal, but for me this one just works.

What’s a solution? Simply put, a collection of projects. To over-simplify, you can compare a solution to a house, and each project to a room. If you’d like to get deeper into it, I suggest you read the documentation.

For our purpose, we simply add a solution to our repo so we can easily browse the files in the solution explorer, nothing more than that.

  1. Double click the repo you cloned to open it
  2. Click new under solutions and choose PowerShell Script Project under the PowerShell section. Note! make sure you uncheck both “create directory for solution” and “create new git repository”
  3. Give it a friendly name and hit ok

This slideshow requires JavaScript.

Now, browse to the solution explorer window and you can see VS created a folder tree starting with the Solution Name at the top, followed by the project name and inside a few files.

Without going too deep into project and solution concept, by creating the 2 we utilized built-in VS viewer to view our files in a convenient way

  • Right click the project and choose Add to add new or existing files to your project
  • Once completed, go to the team explorer tab (next to solution explorer) and click on changes. Here you can see all the files that were created locally and need syncing to the cloud GitHub repo
  • Enter a comment for your commit (mandatory) and choose commit all and sync to sync your local copy to the cloud. Here you can see all the “project” and “solution” files that VS added to your repo to make it readable inside the VS console

commit

if you haven’t done it already, enter your github credentials and your files are now synced.

That’s it. You can now add more files locally and “commit” them to the cloud. You can also add files to the cloud and sync them down to your client by choosing the sync option in the Team explorer tab

Remember that every time you make a change to a file and save it locally you need to commit it so it is in sync. You can commit multiple changes to multiple files in a single commit

Upcoming…

  • Sync Visual Studio Team Services repository to Visual Studio Community Client
  • Start a project locally and sync to a cloud repo (the other way around)

And even further down the road…

  • Repositories, projects and how they all fit together (a short and quick explanation to the development process from a non-development person)
  • Use versions for your files (yes, you can rollback and see a full history of your changes)

One last note

There are multiple ways and tools to achieve the same goal – sync files between a cloud repo and a desktop code editor client.

Some use Git sync client like the wonderful Tortoisegit and edit their code it other editors like VS code or even NotePad++

This is by no means the best or only way, but it’s the one I found most convenient for myself. Do you have a better one? Leave a comment and let me know!

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