Page 26 - MSDN Magazine, June 2017
P. 26

DEVOPS
Git Internals for
Visual Studio Developers
Jonathan Waldman
In my commit to Git DevOps article (msdn.com/magazine/ mt767697), I explained how the Git version control system (VCS) differs from centralized VCSes with which you might already be familiar. I then demonstrated how to accomplish certain Git tasks using the Git tooling in Visual Studio. In this article, I’ll summarize relevant changes to how Git works within the newly released Vi- sual Studio 2017 IDE, discuss how the Git repo is implemented in the file system, and examine the topology of its data store and the structure and content of its various storage objects. I’ll conclude with a low-level explanation of Git branches, providing a perspec- tive that I hope will prepare you for more advanced Git operations I’ll present in upcoming articles.
Note: I use no servers or remotes in this article—I’m exploring a purely local scenario that you can follow using any Windows machine with Visual Studio 2017 and Git for Windows (G4W) installed (with or without an Internet or network connection). This article is an introduction to Git internals and assumes you’re familiar with Visual Studio Git tooling and basic Git operations and concepts.
Visual Studio, Git and You
Git refers not only to the repository (“repo”) that contains the version-control data store, but also to the engine that processes commands to manage it: Plumbing commands carry out low-level operations; porcelain commands bundle up plumbing commands
in macro-like fashion, making them easier if less granular to invoke. As you master Git, you’ll discover that some tasks require the use of these commands (some of which I’ll use in this article), and that invoking them requires a command-line interface (CLI). Unfor- tunately, Visual Studio 2017 no longer installs a Git CLI because it uses a new Git engine called MinGit that doesn’t provide one. MinGit (“minimal Git”), introduced with G4W 2.10, is a portable, reduced-feature-set API designed for Windows applications that need to interact with Git repositories. G4W and, by extension, MinGit, are forks of the official Git open source project. This means they both inherit the official Git fixes and updates as soon as they’re available—and it ensures that Visual Studio can do the same.
To access a Git CLI (and to follow along with me), I recommend installing the full G4W package. While other Git CLI/GUI tooling options are available, G4W (as MinGit’s official parent) is a wise choice—especially because it shares its configuration files with MinGit. To obtain the latest G4W setup, visit the Downloads section at the site’s official source: git-scm.com. Run the setup program and select the Git Bash Here checkbox (creates a Git command-prompt window) and the Git GUI Here checkbox (creates a Git GUI window)—which makes it easy to right-click a folder in Windows Explorer—and select one of those two options for the current folder (the “Bash” in Git Bash refers to Bourne Again Shell, which presents a Git CLI in a Unix shell for G4W). Next, select Use Git from the Windows Command Prompt, which configures your environment so that you can conve- niently run Git commands from either a Visual Studio package man- ager console (Windows PowerShell) or a command-prompt window.
If G4W is installed using the options I’ve recommended here, Figure 1 depicts the communication pathways that will be in effect when communicating with a Git repo: Visual Studio 2017 uses the MinGit API while PowerShell and command-prompt sessions use the G4W CLI—a very different communication pathway en route to the Git repo. Although they serve as different communica- tion endpoints, MinGit and G4W are derived from the official Git source code—and they share their configuration files. Notice that
This article discusses:
• Changes to how Git works within Visual Studio 2017
• How the Git repo is implemented in the file system
• The topology of its data store and the structure and content of its storage objects
• How Git internally defines a branch
Technologies discussed:
Visual Studio 2017, Git for Windows 2.10, Windows PowerShell
22 msdn magazine
















































































   24   25   26   27   28