Update-GitRepository

Updates the working directory of a Git repository to a specific commit.

Syntax

Update-GitRepository [[-RepoRoot] <String>] [[-Revision] <String>] [<CommonParameters>]

Description

The Update-GitRepository function updates a Git repository to a specific commit, i.e. it checks out a specific commit.

The default target is "HEAD". Use the Target parameter to specifiy a different target

It defaults to the current repository. Use the RepoRoot parameter to specify an explicit path to another repo.

This function implements the git checkout <target> command.

Parameters

Name Type Description Required? Pipeline Input Default Value
RepoRoot String

Specifies which git repository to update. Defaults to the current directory.

false false (Get-Location).ProviderPath
Revision String

The revision checkout, i.e. update the repository to. A revision can be a specific commit ID/sha (short or long), branch name, tag name, etc. Run git help gitrevisions or go to https://git-scm.com/docs/gitrevisions for full documentation on Git's revision syntax.

false false HEAD

EXAMPLE 1

Update-GitRepository -RepoRoot 'C:\Projects\LibGit2' -Target 'feature/ticket'

Demonstrates how to checkout the 'feature/ticket' branch of the given repository.

EXAMPLE 2

Update-GitRepository -RepoRoot 'C:\Projects\LibGit2' -Target 'refs/tags/tag1'

Demonstrates how to create a detached head at the tag 'tag1'.