Those working with Visual Studio Code (VSCode) for their integrated development / scripting environments will likely notice the native Git integration that provides visibility and control over a local repository. While this integration is fairly solid on its own, the addition of Git Lens, an extension available in the marketplace, really enhances the user experience. I recently added the extension to my workstation to help with seeing blame, commit comparisons, and easily find the rationale behind a particular line or grouping of code.
While it’s certainly possible to tease apart this information via the Source Control screen, it’s really handy to have it built directly into the file being edited. To install Git Lens, simply navigate to the Extensions panel and search for “git lens” to find and install the extension or visit the Git Lens marketplace page. Once installed, a quick reload window inside of VSCode will get you started.
Quick Reminder: I live stream ever week on Tuesdays and Thursdays on Twitch! Drop a follow, enable notifications, and come join in the adventure.
Providing a Git Path to Git Lens
In the event that
git.exe is not part of your system path variable, which was my situation on a Windows 10 workstation, you will see this error:
GitLens was unable to find Git. Please make sure Git is installed. Also ensure that Git is either in the PATH, or that 'gitlens.advanced.git' is pointed to its installed location.
Assuming you have GitHub for Windows installed, the location of the executable is not automatically added to the path variable. You can either add it to the path variable as outlined in this Stack Overflow thread, or supply the path directly to the Visual Studio Code preferences. I opted to edit the preferences. To do this:
- In Visual Studio Code, navigate to File > Preferences > Settings (or press
Ctrl + ,on PC).
- Enter the search string
gitlens.advanced.gitto find the git path configuration.
- Highlight the configuration line and click the “edit pencil” to copy the configuration over to your User Settings JSON file. You could also just add the line by hand, if desired.
- Enter the full path to your
git.exelocation. Make sure to escape the backslashes by using two of them.
- For example, my path is:
With that done, save the User Settings configuration and perform a reload window.
Working with Git Lens
At this point the Git Lens documentation is your friend. In a nutshell: once you open a folder containing a git repository, all sorts of new details will bubble up. This includes blame annotations, recent change annotations, code lens (recent change and author details at the top of your code), new comparison tools, and a detailed navigation window. The integration is seamless and intuitive, becoming almost instinctive within a few minutes of working with versioned code files.