Set-GitConfiguration

Sets Git configuration options

Syntax

Set-GitConfiguration [-Name] <String> [-Value] <String> [-Scope {System | Xdg | Global | Local}] [-RepoRoot <String>] [<CommonParameters>]
Set-GitConfiguration [-Name] <String> [-Value] <String> -Path <String> [<CommonParameters>]

Description

The Set-GitConfiguration function sets Git configuration variables. These variables change Git's behavior. Git has hundreds of variables and we can't document them here. Some are shared between Git commands. Some variables are only used by specific commands. The git help config help topic lists most of them.

By default, this function sets options for the current repository, or a specific repository using the RepoRoot parameter. To set options for the current user across all repositories, use the -Global switch. If running in an elevated process, Set-GitConfiguration will look in $env:HOME and $env:USERPROFILE (in that order) for a .gitconfig file. If it can't find one, it will create one in $env:HOME. If the HOME environment variable isn't defined, it will create a .gitconfig file in the $env:USERPROFILE directory.

If running in a non-elevated process, Set-GitConfiguration will look in $env:HOME, $env:HOMEDRIVE$env:HOMEPATH, and $env:USERPROFILE (in that order) and use the first .gitconfig file it finds. If it can't find a .gitconfig file, it will create a .gitconfig in the $env:HOME directory. If the HOME environment variable isn't defined, it will create the .gitconfig file in the $env:HOMEDRIVE$env:HOMEPATH directory.

To set the configuration in a specific file, use the Path parameter. If the file doesn't exist, it is created.

This function implements the git config command.

Parameters

Name Type Description Required? Pipeline Input Default Value
Name String

The name of the configuration variable to set.

true false
Value String

The value of the configuration variable.

true false
Scope ConfigurationLevel

Where to set the configuration value. Local means the value will be set for a specific repository. Global means set for the current user. System means set for all users on the current computer. The default is Local.

false false Local
Path String

The path to a specific file whose configuration to update.

true false
RepoRoot String

The path to the repository whose configuration variables to set. Defaults to the repository the current directory is in.

false false

EXAMPLE 1

Set-GitConfiguration -Name 'core.autocrlf' -Value 'false'

Demonstrates how to set the core.autocrlf setting to false for the repository in the current directory.

EXAMPLE 2

Set-GitConfiguration -Name 'core.autocrlf' -Value 'false' -Global

Demonstrates how to set a configuration variable so that it applies across all a user's repositories by using the -Global switch.

EXAMPLE 3

Set-GitConfiguration -Name 'core.autocrlf' -Value 'false' -RepoRoot 'C:\Projects\LibGit2.PowerShell'

Demonstrates how to set a configuration variable for a specific repository. In this case, the configuration for the repository at C:\Projects\LibGit2.PowerShell will be updated.