Configure Git

Completed

To start with Git, you first need to install the Git client package. This package will allow 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 Download Git.

During the installation wizard, you can mostly use the default settings. The installation wizard suggests the Vim editor by default, but unless you are 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 is checked during installation is the usage of the Git Credential Manager. This will handle authentication with Azure DevOps, older Team Foundation Services, and GitHub within your Windows environment. The credentials will be securely stored in Windows Credential Manager. The .NET Framework (currently v4.5.1 or later) also needs to be installed.

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.

Within the Credential Manager, you can choose between Web Credentials and Windows Credentials. If you connect to an Azure DevOps organization or a GitHub account, your credentials will be stored in the Windows Credentials section under Generic credentials. If you ever need to modify your username or password, you can modify or remove the credentials in this window.

Azure DevOps often uses PAT (Personal Access Tokens) to connect your development environment to a repository. These PATs have a maximum expiration date of one year. Whenever you generate a new PAT within Azure DevOps, you need to modify the credentials in Credential Manager.

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 will be 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 will open 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 will have 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"