Add-GitItem

Promotes changes to the Git staging area so they can be saved during the next commit.

Syntax

Add-GitItem [-Path] <String[]> [[-RepoRoot] <String>] [-PassThru] [<CommonParameters>]

Description

The Add-GitItem function promotes new/untracked and modified files to the Git staging area. When committing changes, by default Git only commits changes that have been staged. Use this function on each file you want to commit before committing. No other files will be committed.

Use the PassThru switch to get IO.FileInfo and IO.DirectoryInfo objects back for each file and directory added, respectively. If the items are already added or were unmodified and not added to the staging area, you'll still get objects back for them.

This function implements the git add command.

Related Commands

Parameters

Name Type Description Required? Pipeline Input Default Value
Path String[]

The paths to the files/directories to add to the next commit.

true true (ByValue, ByPropertyName)
RepoRoot String

The path to the repository where the files should be added. The default is the current directory as returned by Get-Location.

false false (Get-Location).ProviderPath
PassThru SwitchParameter

Return IO.FileInfo and/or IO.DirectoryInfo objects for each file and/or directory added, respectively.

false false False

EXAMPLE 1

Add-GitItem -Path 'C:\Projects\LibGit2'

Demonstrates how to add all the items under a directory to the next commit to the repository in the current directory.

EXAMPLE 2

Add-GitItem -Path 'C:\Projects\LibGit2\Functions\Add-GitItem.ps1','C:\Projects\LibGit2\Tests\Add-GitItem.Tests.ps1'

Demonstrates how to add multiple items and files to the next commit.

EXAMPLE 3

Get-ChildItem '.\LibGit2\Functions','.\Tests' | Add-GitItem

Demonstrates that you can pipe paths or file system objects to Add-GitItem. When passing directories, all untracked/new or modified files under that directory are added. When passing files, only that file is added.

EXAMPLE 4

Add-GitItem -Path 'C:\Projects\LibGit2' -RepoRoot 'C:\Projects\LibGit2'

Demonstrates how to operate on a repository that isn't the current directory.

EXAMPLE 5

Get-ChildItem | Add-GitItem

Demonstrates that you can pipe IO.FileInfo and IO.DirectoryInfo objects to Add-GitItem. Plain strings are also allowed.

EXAMPLE 6

Add-GitItem -Path 'file1','directory1' -PassThru

Demonstrates how to get IO.FileInfo and IO.DirectoryInfo objects returned for each file and directory, respectively.