Visual Studio Code: How to integrate Git

Keeping in-step with the clones

Visual Studio Code is a new, lightweight, cross-platform and open source code editor that you can download for free at

In the second of this short series of articles, published in association with Microsoft, Tech Evangelist Sergii Baidachnyi, will dive into the editor's Git-related features. (In case you missed it, check out the first article: Visual Studio Code: The top five features.)

Sergii uses a Mac for this demo but VS Code works on Windows and Linux computers as well.

Working with local Git repository

Assuming that you have no trouble installing Git on your local workstation, once you’ve done so you can start working with it directly from Visual Studio Code.

First, you need to initialize a local repository for your current project and add your files there. It’s easy to do this by clicking Initialize Git repositoryin Git view.

This button will start the init command for Git and will add all of the files automatically. Now you’re ready to work with Git locally.

Working with files locally gives you access to all the standard commands. By clicking any file and activating the context menu you can put the file on Stage:

And using the menu at the top of the Git view you can commit changes or get access to Git output:

Finally, clicking the branch name in the status bar will open the Git Tool’s command line.

Using the command line, you can execute commands such as git checkout and git branch.

Both commands have only one parameter: the name of a branch. Git checkout allows you to checkout files to a new or existing branch and git branch allows you to switch VS Code to a new or existing branch.

Using Git view you can see which files have changed. After clicking on them you can review the current and previous versions of the file. VS Code highlights all of the changes as seen in this example:

Visual Studio Team Service as a provider

Git is just a platform and it requires a provider. If you are not going to set up your own infrastructure, you can use GitHub or Visual Studio Team Service as a provider. Let’s go with Visual Studio Team Service.

Visual Studio Team Service allows up to five developers per account for free, and lets you create any number of projects. It also gives you access to additional features like sprint planning tools, task and Kanban boards, a virtual team room, and more.

And, of course, Visual Studio Team Service supports Git. This means that Visual Studio Code and Visual Studio Team Service can be used together. Activate your free Visual Studio Team Service account at

Once you get access to Visual Studio Team Service, you can create a project. In this case, a "project" means everything that is related to the lifecycle of the application: a repository, team room, and so on. Note that Visual Studio Team Service supports two types of version control systems, including Git.

In this case, select Git:

After the project is created you need to do one more thing inside Visual Studio Team Service – open your profile and use the Security tab to apply alternate authentication credentials. By default, Visual Studio Team Service uses a Live ID for authentication, but Git tools don’t support Live ID.

One more step on the server side is getting a URL that you will use as a remote repository in Git. When you navigate to the project and open the CODE tab, you will see the URL – copy it for the next step.

That’s it for the server side; now it’s time to configure your Mac. First you need to provide Git with your username, which you defined in Visual Studio Online as an alternate credential: :

git config --global

You can create your alternate credentials in a terminal window within Visual Studio Code. It’s better to do it in a terminal window within VS Code because it will open with the context of your workspace. Make sure that you have associated Git with the current workspace prior to executing the next command. Finally, you need to add the reference to the remote repository:

git remote add origin</h

And push existing local files to the remote repository:

git push -u origin –all

That’s it. Reopen Visual Studio Code, and you should see that most of the menu items in the Git tab are now enabled:

You can start coding and commit all changes to Visual Studio Team Service.

GitHub as a provider

If you don’t already have a GitHub account, you can create one at Once you have a GitHub account, you can create a new repository or use an existing one. In the screenshot below you can see how to create a new repository with the New Repository button on the main page.

Once your repository is created, copy the link for cloning (see below) which will be used to initialize your Git system:

The next step is to open a terminal window in order to setup GitHub as a remote repository. To open a terminal window, I often use the VS Code context menu by selecting any file in the Explore sidebar. If you don’t have any files in the Explore side bar, don’t worry, you still can open a terminal window in VS Code directly.

To do so, you need to activate the Command Palette using the View menu item or ⇧⌘P hot key combination. Using the Command Palette, you can call a terminal window in the context of the folder:

In this case, the terminal window doesn’t have the context of a working folder. So, you’ll need to navigate it manually. Using a terminal window, you can associate git with a user name that will be shown in commits history:

git config --global sbaidachni

And clone the GitHub repository to the local folder using the link which we copied earlier:

git clone

If the operation is successful, you should see something like this:

That’s it – now you can use Visual Studio Code to open the cloned folder. VS Code will read all of the information about the repository automatically. You can now start coding..

Git and deployment

Finally, let’s discuss how to use the Git and Visual Studio Code integration features to implement deployment tasks to the cloud. Visual Studio Code doesn’t have any direct integration with Microsoft Azure (Microsoft’s cloud) yet, you can still deploy your project to the cloud with minimal effort.

To start working with Azure, you’ll need an Azure account. You can sign up for a trial account at or use other options such as BizSpark, DreamSpark and MSDN subscriptions. Once you have an account, access the management portal at

To start experimenting with Azure, create a project that contains a single html file. Later on you can create node.js or ASP.NET project – the process will be the same.

Before starting to work with the Azure portal, you need to open a Git view and initialize a local git repository. Now, open the management portal using and create a new Web Application:

With the Web App template, you can easily create hosting storage for your site and deploy almost anything to it, including PHP, Node.js, ASP.NET and other Web applications.

Once the empty web site is deployed, open the Settings and start configuring the deployment:

As you’ll see, Microsoft Azure supports several different sources. You can get your source code from OneDrive, Dropbox, and local Git repositories, GitHub and Visual Studio Online. As Visual Studio Code currently only supports the last three options, you can select any of the options in the menu.

For our purposes, select Local Git Repositories. You’ll see that Azure will add a Git clone URL to the configuration of the site.

Note that you need to setup FTP deployment credentials to start working with Git. You can visit Settings and provide credentials using Deployment credentials tab.

When the credentials are ready, you can continue with Git setup on your local machine. You need to copy the Git clone url from the Azure portal and open a terminal window in context of the working folder.

Because we have already initialized a local Git repository, we can associate it with our remote repository and push the initial commit by calling the following commands:

git remote add azure <url> git push –u azure master

If everything is OK, you can find your deployment on the Continuous Deployment tab:

And you can use the site URL to open the web site:

Right after the initial commit, you can close the Terminal window and continue to work with VS Code and perform all Git activities there. That’s all for this article; check back next week for the next technical article in this Visual Studio Code series!. ®

Similar topics

Broader topics

Other stories you might like

  • Cheers ransomware hits VMware ESXi systems
    Now we can say extortionware has jumped the shark

    Another ransomware strain is targeting VMware ESXi servers, which have been the focus of extortionists and other miscreants in recent months.

    ESXi, a bare-metal hypervisor used by a broad range of organizations throughout the world, has become the target of such ransomware families as LockBit, Hive, and RansomEXX. The ubiquitous use of the technology, and the size of some companies that use it has made it an efficient way for crooks to infect large numbers of virtualized systems and connected devices and equipment, according to researchers with Trend Micro.

    "ESXi is widely used in enterprise settings for server virtualization," Trend Micro noted in a write-up this week. "It is therefore a popular target for ransomware attacks … Compromising ESXi servers has been a scheme used by some notorious cybercriminal groups because it is a means to swiftly spread the ransomware to many devices."

    Continue reading
  • Twitter founder Dorsey beats hasty retweet from the board
    We'll see you around the Block

    Twitter has officially entered the post-Dorsey age: its founder and two-time CEO's board term expired Wednesday, marking the first time the social media company hasn't had him around in some capacity.

    Jack Dorsey announced his resignation as Twitter chief exec in November 2021, and passed the baton to Parag Agrawal while remaining on the board. Now that board term has ended, and Dorsey has stepped down as expected. Agrawal has taken Dorsey's board seat; Salesforce co-CEO Bret Taylor has assumed the role of Twitter's board chair. 

    In his resignation announcement, Dorsey – who co-founded and is CEO of Block (formerly Square) – said having founders leading the companies they created can be severely limiting for an organization and can serve as a single point of failure. "I believe it's critical a company can stand on its own, free of its founder's influence or direction," Dorsey said. He didn't respond to a request for further comment today. 

    Continue reading
  • Snowflake stock drops as some top customers cut usage
    You might say its valuation is melting away

    IPO darling Snowflake's share price took a beating in an already bearish market for tech stocks after filing weaker than expected financial guidance amid a slowdown in orders from some of its largest customers.

    For its first quarter of fiscal 2023, ended April 30, Snowflake's revenue grew 85 percent year-on-year to $422.4 million. The company made an operating loss of $188.8 million, albeit down from $205.6 million a year ago.

    Although surpassing revenue expectations, the cloud-based data warehousing business saw its valuation tumble 16 percent in extended trading on Wednesday. Its stock price dived from $133 apiece to $117 in after-hours trading, and today is cruising back at $127. That stumble arrived amid a general tech stock sell-off some observers said was overdue.

    Continue reading

Biting the hand that feeds IT © 1998–2022