How to compare different branches in Visual Studio Code

2021 answer

Here is the step by step guide:

  1. Install the GitLens extension: GitLens
  2. Then, Click on Source Control:

Source Control

  1. Click on Search & Compare

Click on Search & Compare

  1. Click on Compare References

Compare References

  1. Select the branches you want to compare:

Select Branches

  1. Now, You can select any file for which you want to see the diff from Search & Compare

View Diff


UPDATE

Now it's available:

https://marketplace.visualstudio.com/items?itemName=donjayamanne.githistory

Until now it isn't supported, but you can follow the thread for it: GitHub


Use the Git History Diff plugin for easy side-by-side branch diffing:

https://marketplace.visualstudio.com/items?itemName=huizhou.githd

Visit the link above and scroll down to the animated GIF image titled Diff Branch. You'll see you can easily pick any branch and do side-by-side comparison with the branch you are on! It is like getting a preview of what you will see in the GitHub Pull Request. For other Git stuff I prefer Visual Studio Code's built-in functionality or Git Lens as others have mentioned.

However, the above plugin is outstanding for doing branch diffing (i.e., for those doing a rebase Git flow and need to preview before a force push up to a GitHub PR).


Update: As of November, 2020, Gitlens appears within VSCode's builtin Source Control Panel

I would recommend to use: Git Lens.

enter image description here