How to use Git and GitHub for Microsoft development

Microsoft’s development tools offer many ways to work with Git source control, from plug-ins to direct integration

How to use Git and GitHub for Microsoft development

Microsoft’s acquisition of GitHub is complete, and former Xamarin CEO Nat Friedman is now in charge of the cloud code management service. It wasn’t a surprising acquisition: Over the last few years, Microsoft’s own development processes have taken a deeper and deeper dependency on Git and GitHub. And GitHub’s own management issues made it hard for the company to move forward, and after a short bidding war Microsoft stepped up to take over.

You only have to look at GitHub’s annual State of the Octoverse report to see how important it is to Microsoft. In the Top 10 projects three are key Microsoft tools, and three more are important open source projects that are used across Microsoft platforms. Microsoft is also the largest commercial contributor to open source projects hosted on GitHub, with more than 7,700 commits in the last year.

Projects like .Net Core, PowerShell Core, F#, C#, the Roslyn compiler, Visual Studio Code, and TypeScript are hosted on GitHub, with open design and development, and with significant third-party input. It’s also the back end behind Microsoft’s new Docs documentation service, with pull requests available for any documentation. Even Windows uses Git, though it’s on private internal repositories using Microsoft’s Virtual File System for Git to handle the sheer scale of its code base, downloading only assets that are needed rather than an entire repository.

Git in Visual Studio Code

With Git and GitHub everywhere at Microsoft, it’s also built into Microsoft’s developer tools and into how developers build apps on Windows and for Azure. When you install a new copy of Visual Studio Code, it encourages you to download and install the Windows Git client, so you can connect to any Git-based repository, whether you’re using GVFS, using a local Git install, or have an account on GitHub, GitLab, or any other cloud-hosted Git-based service.

The Git Windows client is a command-line tool. Available in 32- and 64-bit versions, it’s a simple way of integrating Git functionality into Windows and into Windows developer tools. Installing it is easy enough, with Windows Explorer integration for its own Bash-based shell and in Windows’s own command line. If you haven’t installed Visual Studio Code, it’s a download option from the Git Windows installer, and it can be set up as the default editor for Git.

While the client recommends using Git Bash to avoid changing your Windows PATH, this isn’t really an issue, especially if you’re planning on using it with other development tools and from inside the Windows command line. I recommend installing with command-line support, and although this doesn’t give access to Unix-style tools that are bundled with Git, it lets you access Git not only from the Windows command line but also from the terminal built into Visual Studio Code.

Git for Windows uses OpenSSL by default for secure connections. This used to be more of an issue than it is now, because Windows 10 now offers built-in SSL tools. There is an alternative option that supports using the Windows Secure Channel tools, which might be preferable if you need to lock down access to a local Git repository that’s secured with a corporate certificate stored in Active Directory.

Using Git with Windows

Recent Windows 10 builds have added support for Unix-style line-endings in Windows text editors (including Notepad!). That makes the Git line-ending conversion option less important, but it’s there for older versions of Windows and means that cross-platform code checks out with Windows-style line endings and checks back in with Unix-style. Using this option, you can use any Windows editor to edit repository code without worrying about line endings affecting build pipelines or deployment tools. Similarly, improvements in the Windows console mean it’s easier to work with Git in the default console without having to install and use MinTTY as an alternative terminal for Git.

Once installed, Git for Windows can be accessed from any Windows command line (though you’ll need to install a Unix version for Windows Subsystem for Linux [WSL]), including the built-in terminal in Visual Studio Code.

You’ll probably want to automatically check for updates, because it’s a fast-moving project with regular releases. If you’re moving from PC to PC, there’s also a portable version that runs from a thumb drive, so you can bundle up most of your development tools onto a single drive and carry them with you.

You can check out code from any Git repository using Git commands on the Windows command line or through the Visual Studio Code terminal. A Git view of a folder shows changes and gives quick access to common Git commands. You can update your local copy, stashing changes or committing updates. It’s easy enough to quickly create a new branch from a copy of a master, simplifying the process of working with shared code.

Integrating Git into Visual Studio Code makes a lot of sense. Microsoft can build on a familiar open source tool in a development environment that’s been widely adopted by open source communities. There’s no need to learn new commands, and you get the option of using the command line or the mouse, whichever UI option you prefer.

Git and GitHub in Visual Studio

If you’re using Visual Studio, there are plenty of tools for integrating your code with remote repositories. Current builds have support for Git built-in, using the connect tool in the Team tab to open a repository. You can use a local Git repository, or work with Git in Azure Devops and Visual Studio Team Services. Code can be quickly branched for your own work, creating local branches from remote masters. As you add commit statements, you’re creating documentation, ready to merge your changes back into the master branch via a pull request. An initial synchronization creates a copy of your local branch on the remote repository, where you can push changes and create a pull list ready for code review.

GitHub has its own Visual Studio extension, which can be installed with Visual Studio or added later. There’s support for more secure connections, via two-factor authentication. Repositories attached to your account are one click away, and you can create new repositories in the standard or enterprise services from within Visual Studio, including publishing existing projects. With the extension, GitHub becomes part of the Team Explorer view, including managing pull requests.

Other Git tools for Windows developers

Visual Studio Code users can find third-party GitHub tools in the Visual Studio Marketplace, with support for GitHub flows. Other Git-based extensions support specific Git options and workflows, including the popular Gitflow. You’ll also find tools for tracking issues and notifications, which with the latest GitHub features should make Visual Studio Code a useful hub for your devops tasks. Additional support comes from a desktop tool that brings the GitHub user experience to your development PC, supporting collaborative development and adding visual tools to compare diffs between branches as part of code reviews.

Version control is key to modern devops, and adding Git to Windows and to Microsoft’s development tools is an important step towards delivering responsive, agile development. With Git built into Visual Studio, and with plenty of Git-focused tools for Visual Studio Code, there’s really no excuse for not taking advantage of it.

Copyright © 2018 IDG Communications, Inc.