Search
Close this search box.

Git Blog

Releasing the Power of Git

GitLens Tips

5 Advanced Tips for How to Use GitLens in VS Code

GitLens is a Git extension that integrates seamlessly with Visual Studio Code. In fact, with over 14 million installs, it’s one of the most popular Git extensions on the VS Code Marketplace. GitLens earned its popularity because of its ability to unlock valuable authorship information, helping users navigate a project’s revision history, and much more. 

Even if you’re a long time GitLens user, you may find that the tips in this article will uncover GitLens capabilities you weren’t aware of before. If you’re new to GitLens, don’t worry! While these are advanced tips, you can apply any and all of these tips in your workflow today.  Sign up for GitLens+ for free so you can follow along with the tips covered in this article. 

Unleash the full power of Git in VS Code – Sign up for GitLens+ to access powerful features like Worktrees and Visual File History!

Sign up for GitLens+ for free!

Change GitLens Blame Hovers

GitLens exposes annotations on every line of code, providing even more information via hovers. Hovers can display detailed blame information like commit message, author information, commit ID, and more. All of this information can be accessed by hovering your cursor over a specific section of code. 

To modify how the blame hovers behave in GitLens, open the command palette in VS Code by typing cmd+shift+P, then type GitLens settings in the command palette, and hit enter

Next, scroll down to the Hovers section. You can turn this entire feature on or off by selecting and deselecting the checkbox immediately to the left of the Hovers title. Additionally, you can customize what your hovers display and how they will behave by selecting the subsequent checkboxes along the Hovers section.

To customize your hovers to appear when you hover over a line of text rather than just the annotation, select the dropdown menu beneath Show hovers for the current line and choose line & annotation

Now, you can hover your cursor over the annotation, or any part of a line of code, to access GitLens hover information.

GitLens Settings: Configure Date and Time Format

GitLens allows you to modify date and time settings, making it extremely easy for you to localize the time and display your preferred format. To adjust the GitLens settings for date and time, open the command palette in VS Code, type GitLens settings, and hit enter. Then, navigate to the Jump to menu section, located on the right side of your screen, and select Dates & Times near the bottom right. 

From here, there are a variety of formatting options available to you. By simply clicking the Allow relative date formatting checkbox, you can format the date as relative time, which would look something like: 1 day ago, or absolute time, which would look something like: July 25th, 2018 7:18 PM

You can also set your Date locale from here. You can choose to default to the VS Code locale or manually set your own. 

The default date format in GitLens is represented as MMMM Do, YYY h:hmma which looks like, July 25th, 2018 7:18 PM. You can easily update the format by clicking into the Date format box and entering your desired format. You might, for example, choose to reflect the date like so: YYYY-MM-DD, which looks like the following: 2018-07-25.

You can follow the process shown below to set the desired date format to customize the Short Date and Time format. If you later find that you’ve made a change that you want to revert or alter, you can always come back to the GitLens settings and make those updates.

Add Keybindings for any GitLens Command

You can add keybindings for any GitLens command that can be accessed from the command palette. A keybinding, or hotkey, is a set of customized keystrokes that execute a specified action. If you find yourself going to the command palette over and over again for the same command, this feature can be extremely useful. 

To create a keybinding, open up the command palette in VS Code and type >GitLens:. This will bring up a list of all the GitLens commands available to you. Next, hover over the command you want to create a hotkey for and select the gear icon that appears on the right. This will bring you to the settings for the command you selected. 

From here, select Keybinding at the top of your screen. A text box will appear and prompt you to create a customized key combination. Enter the desired key combination you want associated with the GitLens command you selected and hit enter. Now, anytime you enter the key combination you created, GitLens will run the associated command. 

Follow this process to create a key binding for any GitLens command. However, if you try to create a keybinding that already exists for another GitLens or VS Code native command, you’ll get a warning message, and it’s recommended you create a new, unique keybinding. 

Customize CodeLens

GitLens leverages CodeLens, another tool that exposes information inside of VS Code. With GitLens, you can customize how CodeLens operations behave. 

To customize how GitLens leverages CodeLens, perform the following actions: Open up the VS Code command palette, type GitLens settings, and hit enter. Next, scroll down to the section titled, Git CodeLens. From here, you have full control over CodeLens, including turning the entire feature on and off by selecting the checkbox immediately to the left of the title Git CodeLens, as well as other fine grain controls. 

As you toggle CodeLens features on and off, you’ll notice that the preview window at the center shows you how your customizations affect the information that CodeLens displays. 

There are a lot of ways you can customize CodeLens to fit your specific workflow, so don’t be afraid to explore these options and really make it your own.

Use Tokens to Customize GitLens Annotations

You have complete control over how GitLens exposes annotations, and there’s an entire set of tokens you can use to completely personalize how that information is presented in the tool. 

To start customizing your GitLens annotations, open up the VS Code command palette, type GitLens settings, and hit enter. At the top of the GitLens settings, you’ll find a section titled, Current Line Blame. Like the other features we’ve covered, you can turn the entire feature on or off with the checkbox to the left of the Current Line Blame title. 

You’ll notice toward the bottom of the section that there’s an option to customize the GitLens annotation format. The default annotation format is ${author,}${agoOrDate}${via`pullRequest}${  • message|50?}. However, if you click into the annotation format box, several available tokens will be exposed that allow you to modify the annotation format.

For example, you could alter the • message|50?} field to display only 10 characters by replacing the |50 with |10. You can also completely re-order where certain GitLens blame annotations appear in the sequence. By default, GitLens blame annotations display the ${author,} information first. However, you can move that field anywhere in the sequence of annotations by simply cutting and pasting it to fit your desired order. 

Additionally, you can customize the way the annotations appear in both the current line blame and the status bar blame. To access the status bar blame, simply scroll down in the GitLens settings to the section titled Status Bar Blame. You could elect to configure the settings of both options to provide the same GitLens blame information, or you can tweak them to show you slightly different information.

Customize GitLens to Fit Your Unique Workflow

These 5 tips were just a glimpse of just how customizable GitLens is. Not only is this tool incredibly feature rich, but you can take it a step further by tailoring it to fit your exact development needs. If you’re looking for more ways to unleash the full power of Git in VS Code and enhance your GitLens experience, check out these additional 11 GitLens Tips

GitLens+ features reduce the time it takes to complete complex tasks in VS Code. Try Visual File History to show a project’s contributors and graphical representation of your contributions.

Sign up for GitLens+ for free!

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.