Git Blog

Releasing the Power of Git

GitLens Tips

11 Tips for Using GitLens in VS Code

GitLens is the number one Git extension for VS Code, helping over 14 million developers unlock the power of Git in their favorite editor! Here are 11 expert tips on how to make the most of using GitLens right now!

Optimize your Git experience with VS Code today – install GitLens to enjoy better project history visualization and insights!

Install GitLens Free!

1. Customize Your GitLens Experience

GitLens is extremely customizable.  While you can customize a lot of VS Code extensions, GitLens gives you very fine-grain control to fine-tune the user experience. 

You can open the interactive settings editor by opening the home section of the GitLens sidebar menu and looking for Interactive settings editor under Get Started. You can also open the interactive settings editor from the Command Palette by searching for GitLens: Open Settings.  

This will bring up a new view that will let you turn entire features on or off with the click of a checkbox. You can also change the behavior of almost any feature through that settings sub-menu on that same view.

2. GitLens Blame Annotations in Multiple Places

GitLens is probably best known for exposing your Git history by highlighting line by line blame annotations. But did you know that hovering over the annotation provides a richer view with clickable links to allow you to interact with that Git reference, pull request, or issue and discover more about that commit? We encourage you to try it for yourself.

You can also see the GitLens blame annotation in the VS Code status bar at the bottom of the window. Hovering over this section also exposes more info and links. 

3. The 3 GitLens File Annotations

GitLens gives you three different ways to help you understand the history of any file in your project. With any file open in VS Code, you can find a GitLens icon in the upper right-hand corner which will let you toggle the File Annotations. Clicking that icon will show three different options:

  • Toggle File Blame 
  • Toggle File Heatmap 
  • Toggle File Changes

File Blame shows the commit and author who last modified each line of a file. This gives you quick insight into how the file arrived at its current state.  

File Heatmap shows how recently lines were changed relative to all the other changes in the file. Blue means it has not changed in a while, and red means there have been recent changes.  

Files Changes highlights any local, unpublished changes, or lines changed by the most recent commit.

4. Open Changes for Any Previous Revision with Alt-click

GitLens allows users to quickly compare versions through the Open Changes with Revisions menu option in the upper right-hand corner. Clicking on the little arrow icon pointing to the left ← will navigate back one revision at a time, showing you all the changes between that commit and the current version.

If you wanted to look at a revision from many commits ago, you could step back one revision at a time, or you can jump back to any revision with an “alt-click”. When you press and hold the alt key/option key on Mac, and then click the left-facing arrow, you will be presented with a list of all the commits that modified that file.  Now you can simply choose which one you want to compare your work against. 

5. Reorder the Sidebar Views

VS Code is a very customizable application, and GitLens builds on top of that customizability.  If you find that you want to change the order of any GitLens sidebar section, you can move it around just by clicking and dragging it to where you want it to live. 

You can even drag the sidebar items between other sidebar menus.  For example, if you want to take the Stashes sidebar item and place it in the Source Control sidebar, you can do that with ease.  You can even drop items into the main sidebar menu to give you faster access to the tools you use most often.

6. There are a Lot of Keyboard Shortcuts

GitLens comes with a lot of keyboard shortcuts right out of the box.  One easy way to discover the full list of shortcuts available is to open the Interactive settings editor and find the Keyboard Shortcuts. There is a shortcut to this section in the right-hand Jump To menu from the settings page if you want to save some scrolling. 

This section of GitLens settings will give you a few options, and gives you the option to search for GitLens under the VS Code “shortcuts” view. Searching ‘GitLens’ will bring up a lot of existing keyboard shortcuts, as well as all the possible commands that can be assigned keybindings.  That’s right, you can create your own keyboard shortcuts for GitLens features! 

7. Persist Search and Compare Results Between Restarts

You can quickly search and compare any previous revision of your work with any other version, including your current HEAD.  This is as simple as searching for the commit hash, 

Git commit message, author, file, specific change, or tag. This will show all the commits ahead and/or behind the revisions are from each other, giving you better insight into how the project has changed over time. 

If you’re going to search or compare certain revisions frequently, you can click the thumbtack icon on the search results to persist the result in the GitLens sidebar menu. The results will stay put, even if you restart VS Code (or your entire machine!).    

8. A Command Palette for GitLens and Git Commands

GitLens users likely already know that you can use the VS Code Command Palette to quickly access any GitLens feature. GitLens also provides Command Palette assistance for common Git commands!  

Open up the Command Palette with a ctl/cmd+shift+P and type GitLens: Git and VS Code will suggest Git Commands like Git branch, reset, merge, and Git rebase, to name just a few. Selecting one of these autocomplete options will guide you through the steps needed to complete your Git action.

9. GitLens Makes the Integrated VS Code Terminal Interactive 

Ask any developer why they love VS Code, and many will tell you they like the layout and the integrated terminal. Having the terminal at your fingertips while you are working on your code is an indispensable tool.  

GitLens makes your experience with the VS Code terminal even better, turning all Git refs shown in the terminal into clickable links that bring up a whole slew of options for how to interact with that Git commit, branch, or tag! 

10. Autolinked Issues

When using the Search & Compare feature in GitLens, found normally at the bottom of the sidebar menu, you will find a section called “Autolinked Issues and Pull Requests”. This section reveals all the GitHub pull requests and issues that were associated with the revisions, giving you better insight into what features and bugs have been addressed between versions. 

11. Visual File History Shows the Scope of Changes

GitLens+ users have access to Visual File History, allowing you to see the evolution of a file. This shows when changes were made and by whom, but also displays the magnitude of those changes, with larger commits shown as larger entries into the grid view.

To access this view, either open the integrated terminal panel and click on GitLens from the top of that view, or search: GitLens: Visual History Timeline from the Command Palette.

Do More with GitLens

These are just a few examples of how to use GitLens for VS Code and become more productive using Git. As you continue to use this popular Git extension, you will find there are numerous ways to unleash the true power of Git in VS Code. We would love to hear how you use GitLens in your work and see your favorite tips and tricks. Please give us a shout on social media and mention @GitLens with your helpful hints!

Of course, if you’re not already using GitLens, the first step to leveraging these awesome tips in your workflow is to install GitLens for VS Code.  It’s free to use and you can get started right now!

Like this post? Share it!

Read More Articles

Make Git Easier, Safer &
More Powerful

with GitKraken
Visual Studio Code is required to install GitLens.

Don’t have Visual Studio Code? Get it now.