Configure Git

Completed

To start with Git, you first need to install the Git client package. This package allows you to execute different Git commands using the command prompt or a GUI client. Visual Studio Code supports Git commands out of the box, but you still need to install the Git application before Visual Studio Code can use those commands.

Git is a free and open source distributed version control system that you easily can install on a Windows machine. You can go here to Installing Git.

During the installation wizard, you can mostly use the default settings. The installation wizard suggests the Vim editor by default, but unless you're familiar with command-based text editors, we recommend that you select Visual Studio Code as Git's default editor because Vim can be difficult for some to use.

Select Visual Studio Code as default editor.

Another important setting you need to make sure it's checked during installation is the usage of the Git Credential Manager. This setting will handle authentication with Azure DevOps and GitHub within your Windows environment. The credentials are securely stored in Windows Credential Manager.

Screenshot of the Enable Git Credential Manager checkbox.

You can find Windows Credential Manager by using the search function in Windows and search for Credential Manager. You can also open the Control Panel and select Credential Manager.

Screenshot of the Credential Manager in the Control Panel.

After you sign in, Git Credential Manager caches a token for future connections to the repository, so Git commands don't prompt for credentials until the token expires. For Azure Repos, Microsoft Entra ID tokens are the recommended authentication method. Personal access tokens (PATs) are an alternative when Entra ID authentication isn't available. If you use a PAT, limit its scope and lifetime, and revoke it when it's no longer needed. For current authentication options, see Use Git Credential Manager to authenticate to Azure Repos.

Screenshot of the Git Generic Credentials.

If you finished installing, you can test that Git is successfully installed on your machine. Open a Command Prompt and type git --version.

The output should display the current installed version.

Screenshot of the Git version output.

If you get a message that the git keyword isn't recognized, you can try to reboot your machine. If you still get the same message, then you can try to reinstall Git.

After you install Git, you need to set some configuration settings. With every commit that you make (a commit is storing files in the Git system), your username and email are stored in Git as well. Therefore, you need to configure them. You can execute the commands with a Command Prompt window, or you can use the Terminal functionality within Visual Studio Code.

Open Visual Studio Code, then select Terminal in the menu bar and then select New Terminal. It opens either a PowerShell prompt or a regular Command Prompt at the bottom of your Visual Studio Code window.

Screenshot of the Terminal prompt in Visual Studio Code.

Settings in Git can be configured on three levels:

  • System: These settings are applied to all users on the computer. If you are configuring these settings on a remote desktop server, all users will have these settings applied. The default editor is a setting that is typically configured on system level.

  • Global: These settings are applied to all repositories for the current user. The settings are stored in a .gitconfig file that you can find at C:\users\$user\.gitconfig. Your username and user e-mail settings are configured on a global level. Each user on the machine has its own .gitconfig file.

  • Local: These settings are applied on one specific repository. If you want to override a setting on system or global level for a particular project, you use the local settings level.

To get a list of your configuration settings, you can use the config --list command.

git config --list

git config --system --list

git config --global --list

git config --local --list

To create or update a setting, you use the config command. With a parameter, you can define on which level you'd like to work. To set the username and email, you can use following commands.

git config --global user.name "Your Name"

git config --global user.email "name@xyz.com"

Updating the default editor can be done by specifying the path to the editor.

git config --global core.editor "path_to_editor.exe"