DEV Community

Cover image for Git Lens: Advanced Git Features
Pratik Kale
Pratik Kale

Posted on

Git Lens: Advanced Git Features

Welcome to the tenth blog of the series!
Now that we have covered Git, GitHub and how to collborate. Let's look at Git Lens a Visual Studio extention which enhances your Git workflow by providing advanced features and insights directly within the editor. It offers a wealth of functionalities, including annotations, code lens, blame annotations, and much more. In this blog post, we will explore the various features of Git Lens, demonstrate how to use them effectively, and discuss some of the pro features available.

Installing Git Lens

Before we dive into the features of Git Lens, let's quickly go over the installation process:

  1. Launch Visual Studio Code.
  2. Open the Extensions view by clicking on the square icon on the left sidebar or by using the shortcut Ctrl+Shift+X.
  3. Search for "Git Lens - Git supercharged" in the Extensions Marketplace.
  4. Click on the "Install" button next to the Git Lens .
  5. Wait for the installation to complete, and then click on the "Reload" button to activate the extension.

With Git Lens installed and activated, let's explore its powerful features.

Git Lens

Annotating Code with Git Blame

Git Lens allows you to view Git blame annotations directly in your code, providing insights into who last modified each line. To enable Git blame annotations:

  1. Open a file in Visual Studio Code.
  2. Right-click on the editor or use the command palette (Ctrl+Shift+P).
  3. Search for "Git Lens: Toggle Line Blame Annotations" and select it.

Git Lens will display annotations alongside each line of code, showing the author and commit details.

Exploring Code History

With Git Lens, you can effortlessly explore the history of a file, view commits, and see detailed information about each commit. Follow these steps to access code history:

  1. Open a file in Visual Studio Code.
  2. Right-click on the editor or use the command palette (Ctrl+Shift+P).
  3. Search for "Git Lens: Show File History" and select it.

Git Lens will display a timeline of commits related to the file. Clicking on a commit will show you the commit message, author, and other relevant information.

Viewing Code Lens

Code Lens is a powerful feature of Git Lens that provides additional contextual information about your code. It displays Git blame annotations, recent commit messages, and the number of references to a particular code block. To enable code lens:

  1. Open a file in Visual Studio Code.
  2. Look for annotations above code blocks, showing Git blame information and commit details.
  3. Hovering over the annotations will reveal additional options, such as viewing the full commit message or navigating to the commit.

Code Lens provides valuable insights into the origin and history of your code, helping you understand its context and evolution.

Pro Features of Git Lens

Git Lens offers additional advanced features through its pro version. Some of the notable pro features include:

  • Code authorship: See author statistics, including lines of code contributed and number of commits.
  • Advanced search: Perform advanced searches within your Git repository, such as searching for specific code snippets or commit messages.
  • File comparisons: Compare the differences between different versions of a file to gain a deeper understanding of code changes. To unlock these pro features, you can purchase a license directly within the extension.

To unlock the pro version you can use the GitHub Student Developer Pack. Git Lens pro is free as long as you are student.

Git Lens

Conclusion

Git Lens is a valuable extension for Visual Studio Code that enhances your Git workflow and provides advanced features directly within the editor. With Git blame annotations, code history exploration, and code lens, you gain insights into the evolution and context of your code. The pro features of Git Lens offer additional capabilities, including code authorship statistics, advanced search functionality, and file comparisons. Install Git Lens today and take advantage of its powerful features to streamline your Git workflow and gain a deeper understanding of your codebase.

Thank you for reading and do let me know your thoughts in comments!

Connect With Me :


Website | Twitter | Instagram | Mail

Top comments (0)