Skip to content

Invoke‑Git

viscalyxbot edited this page Sep 30, 2025 · 2 revisions

SYNOPSIS

Invokes a git command.

SYNTAX

Invoke-Git [-Path] <String> [[-Timeout] <Int32>] [-PassThru] [[-Arguments] <String[]>]
 [<CommonParameters>]

DESCRIPTION

Invokes a git command with command line arguments using System.Diagnostics.Process.

Throws an error when git ExitCode -ne 0 and -PassThru switch -eq $false (or omitted).

EXAMPLES

EXAMPLE 1

Invoke-Git -Path 'C:\SomeDirectory' -Arguments @( 'clone', 'https://github.com/X-Guardian/xActiveDirectory.wiki.git', '--quiet' )

Invokes the Git executable to clone the specified repository to the working directory.

EXAMPLE 2

Invoke-Git -Path 'C:\SomeDirectory' -Arguments @( 'status' ) -Timeout 10000 -PassThru

Invokes the Git executable to return the status while having a 10000 millisecond timeout.

EXAMPLE 3

$result = Invoke-Git -Path 'C:\SomeDirectory' -Arguments @( 'status' ) -PassThru

Invokes the Git executable to return the status and stores the result in the $result variable.

The $result variable will contain a hashtable with the following keys: ExitCode StandardOutput StandardError

EXAMPLE 4

Invoke-Git -Path $script:testRepoPath -Arguments @('config', 'user.name', '"Test User"')

Configures the git user name for the repository located in $script:testRepoPath.

PARAMETERS

-Arguments

The arguments to pass to the Git executable.

Type: String[]
Parameter Sets: (All)
Aliases:

Required: False
Position: 3
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

-PassThru

Switch parameter when enabled will return result object of running git command.

Type: SwitchParameter
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: False
Accept pipeline input: False
Accept wildcard characters: False

-Path

The path to the git working directory.

Type: String
Parameter Sets: (All)
Aliases: WorkingDirectory

Required: True
Position: 1
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

-Timeout

Milliseconds to wait for process to exit.

Type: Int32
Parameter Sets: (All)
Aliases:

Required: False
Position: 2
Default value: 120000
Accept pipeline input: False
Accept wildcard characters: False

CommonParameters

This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters.

INPUTS

None. This function does not accept pipeline input.

OUTPUTS

System.Collections.Hashtable

Returns a hashtable when PassThru parameter is specified containing ExitCode, StandardOutput, and StandardError.

NOTES

RELATED LINKS

Clone this wiki locally