Corrado's Blog 2.0

Online thoughts of a technology funatic

Learning Git with Visual Studio #1

As the vast majority of you i use Git as source control management, and, as many of you, I use it everyday but I feel that I’m just a basic user, so when something goes wrong or I just need to do something more ‘advanced’ i get lost very easily.
Another thing that differentiates me from those geeky developers is that I don’t like using command line to interact with Git, but I prefer to use the same tool I use everyday: Visual Studio.
This series of post are nothing more that my tentative to take some basic notes of my daily Git use as basic user.
There is a lot of documentation around Git, in case you need more detailed info, at this link you will find a comprehensive guide.
The core concept I want to point out here are:

-Git is more than a simple source control system.
-Git is a decentralized and serverless.

Regarding 2nd point: It means that Git doesen’t require you to have a steady connection to a server, in fact you might even decide to not have a server at all and, in case of more developers working on the same code, they work with a local copy of the code and, when they decide to, they can sync their copies and this sync operation might lead to conflicts in case two or more developers changed the same parts of code.
When this happen, fixing all conflicts must be done manually with great attention to prevent that some code modifications got lost (more on this in following episodes)

When we create a new solution with Visual Studio, if we want to use source control with it we need to ‘add it’ to a source management system, Git in this case, since Visual Studio won’t do that automatically for us.
Before creating our first project and connect it to Git we need to install the Git plugin into Visual Studio since this won’t be installed by default, we can do this in different ways:

-At installation time
-Modifying Visual Studio Installation via Visual Studio installer

image

-Add it via Extensions and Updates menu in Visual Studio

image

Done this let’s create a new UWP application (but you can use any project type you like) and note the “Create new Git repository” checkbox

image

If we check it, the new project will be associated with Git and we can use all related functionalities, confirmed by the presence of file status icons behind each file that is part of our solution.

image

All infos related to Git are stored inside hidden .git folder at the root of our solution on disk

image

If we now close the solution, delete the .git folder and reload it, we’ll see that solution is no longer associated with a source control because icons behind the files are gone

image 

How do we connect (or reconnect) a solution to source control? easy, just right click the solution and select Add solution to source control to go back to a connected solution

image

When we associate a project to git source control Visual Studio performs several operations behind the scenes, the most evident one are the inclusion of a couples of files:

-.gitignore that contains a common list of files that don’t have to be considered by source control (e.g. binary files, log files etc)

-.gitattributes configure some git behaviors (like line endings)

We now have our brand new project and we know we can use Git source management system with it directly from Visual Studio, in the next episodes we’ll see how.

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

RSS feed for comments on this post. TrackBack URL

Leave a Response