Version Controlling in Visual Studio Code with GIT

banner

Agenda: In this tutorial, we will

  • Create a new project folder
  • Initialize that to a GIT repository using Visual Studio Code integrated GIT feature
  • Create a new Console application in that repository
  • Track the changes made to the repository and make Commits using Visual Studio Code GIT GUI and Integrated terminal, both
  • Do more operations on repository to explore other features of GIT in Visual Studio Code

Version controlling is the most required feature that a asp.net web development team needs while working in an enterprise environment. GIT is the most popular version controlling system which is open source, free to use, works on Linux based shell scripting, and easy to integrate with any type of IDEs.

Microsoft has done a great job by integrated all the features of GIT within Visual Studio Code editor. This is the reason that Visual Studio code is dominant code editor tool in Software Development Solutions.

Are you worried about the conversion of the version?

It is very important for any developer while working in an enterprise environment. Visit us to avail our expert services.

Pre-requisite

Visual Studio Code must be installed on your system. If not, please navigate to https://code.visualstudio.com and download the installer for it and install it in your system.

Step 1: Create a new Folder on your local system. I am creating it on Desktop. This folder will act as our repository.

version-controlling

Step 2: Right click on the folder and select ‘Open with Code’. This will open the folder in Visual Studio Code editor.

version-controlling

Step 3: You will see 5 big icons on the left panel; the third one is for GIT. Click on that and you will see a small icon of GIT, if you hover over that icon, it will show a tooltip ‘Initialize Repository’. This is used to initialize a folder or a project folder to be a GIT repository so that GIT can track the changes in it.

version-controlling

Step 4: Once you click on the icon, it will ask you to select the folder that you want to initialize to GIT repository. So, select the folder that we created on Desktop.

version-controlling

Step 5: Now, our new folder is GIT enabled repository. Open Integrated terminal, by following the below shown steps or use shortcut “Ctrl + ~ “.

version-controlling

Step 6: Create a new console application by using Asp.net web development core template. Use the below highlighted command and it will create some new files in the repository.

version-controlling

You can notice, on the left side, the third large icon shows ‘7’ as badge count; this means that there are 7 changes to the repository that Visual Studio code has tracked.

version-controlling

Step 7: Compile and run the application using below highlighted command in screenshot. This will make sure that our project template is working fine. Also, this will create a bin folder in the repository and increase the count of tracked changes to ‘20’.

version-controlling

Step 8: Click on the GIT icon on left panel, and you will see the list of files that are added, modified.

version-controlling

‘U’ in front of most files states that these are untracked files. We need to Stage them before committing.

version-controlling

Step 9: Stage the untracked files in repository and you will notice, the ‘U’ status changes to ‘A’ meaning ‘Added’ as tracked files now.

You can directly click on ‘Commit All’ option or you can click on ‘Stage All Changes’.

version-controlling
version-controlling

Step 10: Add a comment in message box and click on commit button, this will commit our changes to repository. GIT will create a HASH Id as well for that commit so that it is track able.

version-controlling

And that’s it. We are done with committing our changes to GIT repository using GIT GUI in Visual Studio Code.

Now we will perform same operations and some other operations through integrated terminal command line tool within Visual Studio Code. We will be using some git commands to perform these operations.

Step 11: Verifying the commits done so far can be achieved with the command mentioned in the screenshot below.

version-controlling

Step 12: To check whether there are any pending changes that are not committed yet, we can use ‘git status’ command.

version-controlling

Step 13: Now, let’s make some changes to Program.cs, and see whether GIT track changes to that file and shows in GIT panel in Visual Studio code.

version-controlling
version-controlling

If you notice in above screenshot, the third icon on left panel, indicate 8 count as the number of changes which were tracked.

Step 14: Since these changes are not staged at all, so they will be treated as untracked. So, we write ‘git add .’ command and it will add these changes to tracked changes and you are then ready for making another commit.

version-controlling

In above screenshot, ‘M’ in front of some file names indicates that these files already exist in project but are modified. Some are with ‘A’ flag, meaning these are newly added files.

Step 15: Commit changes using git command.

version-controlling
version-controlling

You can see that git committed the changes to repository and shows status that 8 files changed and 1 insertion.

Step 16: If you remember, from above, we made 2 commits in total. So, if we hit ‘git log’ command, it should show both commits.

version-controlling

Conclusion

So, finally we concluded that GIT is the easiest to use version controlling system and Visual studio code has made it easier for us to maintain our asp.net web development projects. Hope you enjoyed.

Table of Content
Empower your Business with Team Aegis, CONNECT NOW!
captcha

Scale your Business with our Software Services Now!
Related article

In this article will have look on how to deploy ASP.NET MVC application to Azure Cloud Service using Visual Studio 2017.

The fourth community technology preview was released by Microsoft earlier this week for the upcoming Visual Studio 14 update with Asp.net vNext and .net framework,

Azure function is a service offering by Microsoft Azure which allows a small piece of code to be written for special purpose and can be deployed on cloud resources independently. It is used in building WEB APIs which exposes an endpoint that can be hit by any external consumer and logic can be processed on demand. We can use functions to build web apis which we will be doing in this article and we will also test it with the help of Postman client.

DMCA Logo do not copy