HOWTO · Git

How to Add Git to PATH on Windows

Add Git's cmd directory to the PATH through Environment Variables or a persistent PowerShell change so Git runs from any folder, then verify with git --version.

On this page

To run Git commands from any working directory on Windows, add the directory containing Git’s command-line executable to the PATH environment variable. You can do this in Windows Environment Variables or persistently with PowerShell. Then open a new terminal and check the Git version.

Add Git to PATH on Windows

PATH is a list of directories Windows searches when you enter a command. Add a directory, not the git.exe file itself. For a typical Git for Windows installation, use C:\Program Files\Git\cmd. The sibling bin directory may be useful for other Git utilities, but add it only if you need those tools. If Git is installed elsewhere, locate its cmd directory first.

You can edit either your user Path or the system Path. A user entry applies to your Windows account and normally needs no administrator access. A system entry applies to all users and requires administrator permission.

  1. Search Windows for Edit the system environment variables and open it.

    Search for edit environment variables

  2. In System Properties, select Environment Variables. You can also reach System Properties by right-clicking This PC, choosing Properties, then opening Advanced system settings.

    This PC properties

  3. Under User variables or System variables, select Path, then choose Edit. Choose the user entry for a change limited to your account.

    Edit system variables

  4. Select New, enter the Git cmd directory (for example, C:\Program Files\Git\cmd), and save the dialogs. Do not enter C:\Program Files\Git\bin\git.exe; PATH entries must be directories.

    Add Git to PATH

For PortableGit, the location may be under C:\Users\<user>\AppData\Local\GitHub\PortableGit_<guid>. Confirm the actual installation on your computer, then add its cmd directory. Add its bin directory only when you need the additional utilities there.

Add Git to PATH with PowerShell

PowerShell can persist a directory in your user PATH without replacing the existing entries. The following self-contained example assumes Git is installed in the standard Program Files location. It checks that directory and adds it only when it is not already present. This Windows-specific example is unexecuted in the supplied runtime evidence; confirm the installation location before using it.

$gitCmd = Join-Path $env:ProgramFiles 'Git\cmd'
if (Test-Path -LiteralPath $gitCmd -PathType Container) {
    $userPath = [Environment]::GetEnvironmentVariable('Path', 'User')
    $entries = @($userPath -split ';' | Where-Object { $_ })
    $alreadyPresent = $entries | Where-Object { $_.TrimEnd('\') -ieq $gitCmd.TrimEnd('\') }
    if (-not $alreadyPresent) {
        $newPath = (@($entries) + $gitCmd) -join ';'
        [Environment]::SetEnvironmentVariable('Path', $newPath, 'User')
    }
}

The User target changes the persistent PATH for your account; it does not require an elevated PowerShell window. If Git is installed in another location, set $gitCmd to that installation’s cmd directory. A change to $env:Path alone affects only the current PowerShell process and its child processes, so it is not a persistent replacement for this method.

Verify Git from a new terminal

Close existing Command Prompt or PowerShell windows, open a new one, and run git --version. New terminals receive the updated environment; a terminal that was already open may still have its previous PATH.

Check Git version in Command Prompt

If the command prints a version, Windows can find Git by name. This confirms command discovery; it does not check a repository or your Git configuration.

Troubleshoot when Git is not recognized

If a new terminal reports that git is not recognized, check these items:

  • Confirm Git is installed and that the cmd directory you added exists. The default is commonly C:\Program Files\Git\cmd, but an installer or PortableGit can use another location.
  • In Environment Variables, make sure the directory appears as a Path entry. The entry should end with cmd, not git.exe.
  • Open another new terminal after saving the change. Existing windows do not automatically reload PATH.
  • If you edited the system Path, confirm the change was saved with administrator permission. For a single account, use the user Path instead.

Once the correct directory is on PATH, git --version in a new terminal should display the installed version.