Corrado's Blog 2.0

Online thoughts of a technology funatic

Learning Git with Visual Studio #7

Until now, we worked with a local installation of git and everything was good but once we start working on a project together with someone else we’ll soon discover that we need a way to share our work with other members so working offline is no longer an option.
It’s now time to go online, and in this post we’ll use GitHub as service for host and share our projects.

In order to user GitHub we need to have an account, if you don’t have one, navigate to https://github.com and register:

image

once registration is completed, login and click Start a project button to create a brand new repository, fill form with your data

image

the click Create Repository to create it, after a moment you will have the uri to GitHub repository

image

Now is time to add to Visual Studio plugin the capability to connect to GitHub repository, if not already present go to Tools->Extensions and Updates, select Online on left column and using search box in upper right corner and type github.

The first result should be the extension you need:

image

Select it and click Download to install it, then restart Visual Studio to complete installation.

Now go to Team Explorer, click on the green plug in top toolbar and connect to your GitHub account

image

Sign in with GitHub credential to complete connection of Visual Studio to GitHub.
We can now create or clone a new github repository, let’s clone the repository we created before by clicking clone above GitHub connection.

image

we are now prompted with a list of our repositories, including the one we just created

image

select and click Clone, we’ll now have an empty GitHub project inside Visual Studio, time to add a blank solution using File->New->Project->Other Project Types->Visual Studio Solutions

image

We’ll now see our blank solution inside Solution Explorer

image

Time to add a new project, let’s add a Console Application Project, right click the Solution->Add New Project->Windows Classic Desktop->Console Application

image

and click Ok, the project will be listed under our solution now

image

From the “+” on the left of the items you will now recognize that items are added to local git repository but not committed, let’s add a comment and try to commit the changes

image

Wait! there’s a problem!, what are those files? we don’t need them to be tracked! but since we didn’t added a .gitignore file, git will track all files that are part of our solution.
Let add it before committing the project: In Team Explorer, click Settings->Repository Settings and click Add button next to Ignore File

image

If we now go back to Changes tab, we’ll see this status, and only files making up our solution will be now tracked

image

Let’s click Commit Staged to commit staged and the Commit to complete the commit phase.
Ok, our new project is now tracked by local Git, how to we sync with GitHub?
Let’s select Sync tab, we’ll see something like this picture

image

Let’s click Push to push changes to GitHub and let’s see how they appear on GitHub portal

image

It is an online copy of our local repository.
Let’s add a property to P1 to Program.cs, commit and push the change, we’ll now see the latest commit listed

image

Let’s make a branch dev, and let’s push it, if we have a look online we will see it listed under branches dropdown list

image

It is now evident that GitHub now acts as online hub for all push operation from different team members and relative pull operation when members need to retrieve changes pushed by other developers.
Of course, if two developers works on the same part of code during pull operation conflicts might happen and need to be fixed.
We’ll talk about that… Smile

No Responses to “Learning Git with Visual Studio #7”

RSS feed for comments on this post. TrackBack URL

Leave a Response