VSCode Git Error – Encountered old-style xxx that should be %(prefix)/xxx – (Fixed)

This tutorial teaches you the different methods to solve the VSCode Git Error – Encountered old-style “xxx” that should be “%(prefix)/xxx”.

You can solve VSCode Git Error – Encountered old-style xxx that should be %(prefix)/xxx by deleting the trusted locations without the %(prefix) variable in the C:\Users\username.gitconfig file

We experienced this error while working with the GIT in VS Code to maintain the source code of the node program How to Download a File from AWS S3 in JavaScript (Node JS Environment).

We have solved this error by following the steps explained in the following sections.

Root Cause of the VSCode Git Error – Encountered old-style “xxx” that should be “%(prefix)/xxx”

The local Windows Git configuration lists safe, trusted locations for remote git Repos. It contains all the trusted remote locations that you can interact with.

For example, it contains the trusted locations as below.

[safe]

      directory = //10.15.1.23/myrepo

When working with the CIFS locations, the path must be prefixed with the %(prefix) variable as the following line.

[safe]

      directory = %(prefix)///10.15.1.23/myrepo

The %(prefix) environment variables value is set while compiling the git. It can be configured in the make file before installing it. For example, in the os X installer make file, there is a variable prefix set to using PREFIX:= /usr/local.

The prefix variable is usually set to the location where the git is installed locally, and the %(prefix) variable will be expanded to use this location.

Now let us see how to solve this issue.

Solution – 1 for VSCode Git Error – Encountered old-style “xxx” that should be “%(prefix)/xxx”

To suppress the encountered old-style “xxx” that should be “%(prefix)/xxx” error,

  • Remove the trusted locations without the %(prefix) variable

For example, your .gitconfig file might contain similar lines given below that list the trusted locations.

[safe]

    directory = //10.15.1.23/myrepo

    directory = %(prefix)///10.15.1.23/myrepo2
  1. Open the .gitconfig file is available in the location C:\Users\username\.gitconfig
  2. Remove the line without the %(prefix) and save it.

If you do not find the .gitconfig file in the default location, use the following command and find the .gitconfig file.

git config --list --show-origin

Now you shall interact with your git repository without the error.

If you do not want to remove the offending line, follow the next section to learn how to add the %(prefix) variable to the trusted location line of your repository.

Solution – 2 for VSCode Git Error – Encountered old-style “xxx” that should be “%(prefix)/xxx”

As an alternative solution, you can add your repository path to the trusted location with the %(prefix) variable prepended.

Use the following command to add the repository name with the %(prefix) prepend.

git config --global --add safe.directory %(prefix)///servername/repo_name

Now your .gitconfig will contain lines similar to those below.

[safe]

    directory = %(prefix)///10.15.1.23/myrepo

    directory = %(prefix)///10.15.1.23/myrepo2

Ensure you’re using three slashes after the %(prefix) variable to avoid the trailing slash issue.

Now you shall interact with your git from VS code without the errors.

If you have any questions, feel free to comment below.

Categories GIT

Leave a Comment