New-GitHubGitTree

SYNOPSIS

Create a tree

SYNTAX

Default (Default)

New-GitHubGitTree [-Owner] <string> [-Repo] <string> -Tree <Object[]> [-BaseTree <string>]
 [-Accept <string>] [-WhatIf] [-Confirm]

Body

New-GitHubGitTree [-Owner] <string> [-Repo] <string> -Body <Object> [-Tree <Object[]>]
 [-BaseTree <string>] [-Accept <string>] [-WhatIf] [-Confirm]

ALIASES

This cmdlet has the following aliases,

  • Get-GHNewGitTree

DESCRIPTION

The New-GitHubGitTree cmdlet invokes the POST method of the /repos/{owner}/{repo}/git/trees endpoint (Create a tree)

The tree creation API accepts nested entries. If you specify both a tree and a nested path modifying that tree, this endpoint will overwrite the contents of the tree with the new path contents, and create a new tree structure.

If you use this endpoint to add, delete, or modify the file contents in a tree, you will need to commit the tree and then update a branch to point to the commit. For more information see “Create a commit (https://docs.github.com/rest/git/commits#create-a-commit)” and “Update a reference (https://docs.github.com/rest/git/refs#update-a-reference).”

Returns an error if you try to delete a file that does not exist.

Endpoint: POST /repos/{owner}/{repo}/git/trees API version: 2026-03-10

EXAMPLES

EXAMPLE 1

New-GitHubGitTree -Owner 'octocat' -Repo 'Hello-World' -Tree @(@{ key = 'value' }) -Body @{ key = 'value' }

Invokes POST /repos/{owner}/{repo}/git/trees

EXAMPLE 2

New-GitHubGitTree -Owner 'octocat' -Repo 'Hello-World' -Body @{ tree = @(@{ key = 'value' }) }

Sends the request body from a hashtable, parameters override the keys of -Body

PARAMETERS

-Accept

The Accept header (media type) of the request Default value: application/vnd.github+json

Type: System.String
DefaultValue: ''
SupportsWildcards: false
Aliases: []
ParameterSets:
- Name: (All)
  Position: Named
  IsRequired: false
  ValueFromPipeline: false
  ValueFromPipelineByPropertyName: false
  ValueFromRemainingArguments: false
DontShow: false
AcceptedValues: []
HelpMessage: ''

-BaseTree

The SHA1 of an existing Git tree object which will be used as the base for the new tree. If provided, a new Git tree object will be created from entries in the Git tree object pointed to by ‘base_tree’ and entries defined in the ‘tree’ parameter. Entries defined in the ‘tree’ parameter will overwrite items from ‘base_tree’ with the same ‘path’. If you’re creating new changes on a branch, then normally you’d set ‘base_tree’ to the SHA1 of the Git tree object of the current latest commit on the branch you’re working on. If not provided, GitHub will create a new Git tree object from only the entries defined in the ‘tree’ parameter. If you create a new commit pointing to such a tree, then all files which were a part of the parent commit’s tree and were not defined in the ‘tree’ parameter will be listed as deleted by the new commit.

Body property [ base_tree ]

Type: System.String
DefaultValue: ''
SupportsWildcards: false
Aliases: []
ParameterSets:
- Name: (All)
  Position: Named
  IsRequired: false
  ValueFromPipeline: false
  ValueFromPipelineByPropertyName: false
  ValueFromRemainingArguments: false
DontShow: false
AcceptedValues: []
HelpMessage: ''

-Body

The whole request body as a hashtable or object. Keys that are also available as parameters are overwritten by the parameter values

Type: System.Object
DefaultValue: ''
SupportsWildcards: false
Aliases: []
ParameterSets:
- Name: Body
  Position: Named
  IsRequired: true
  ValueFromPipeline: false
  ValueFromPipelineByPropertyName: false
  ValueFromRemainingArguments: false
DontShow: false
AcceptedValues: []
HelpMessage: ''

-Confirm

Prompts you for confirmation before running the cmdlet.

Type: System.Management.Automation.SwitchParameter
DefaultValue: ''
SupportsWildcards: false
Aliases:
- cf
ParameterSets:
- Name: (All)
  Position: Named
  IsRequired: false
  ValueFromPipeline: false
  ValueFromPipelineByPropertyName: false
  ValueFromRemainingArguments: false
DontShow: false
AcceptedValues: []
HelpMessage: ''

-Owner

The account owner of the repository. The name is not case sensitive.

Path parameter [ owner ]

Type: System.String
DefaultValue: ''
SupportsWildcards: false
Aliases: []
ParameterSets:
- Name: (All)
  Position: 0
  IsRequired: true
  ValueFromPipeline: false
  ValueFromPipelineByPropertyName: true
  ValueFromRemainingArguments: false
DontShow: false
AcceptedValues: []
HelpMessage: ''

-Repo

The name of the repository without the ‘.git’ extension. The name is not case sensitive.

Path parameter [ repo ]

Type: System.String
DefaultValue: ''
SupportsWildcards: false
Aliases: []
ParameterSets:
- Name: (All)
  Position: 1
  IsRequired: true
  ValueFromPipeline: false
  ValueFromPipelineByPropertyName: true
  ValueFromRemainingArguments: false
DontShow: false
AcceptedValues: []
HelpMessage: ''

-Tree

Objects (of ‘path’, ‘mode’, ‘type’, and ‘sha’) specifying a tree structure.

Required unless -Body is used

Type: System.Object[]
DefaultValue: ''
SupportsWildcards: false
Aliases: []
ParameterSets:
- Name: Body
  Position: Named
  IsRequired: false
  ValueFromPipeline: false
  ValueFromPipelineByPropertyName: false
  ValueFromRemainingArguments: false
- Name: Default
  Position: Named
  IsRequired: true
  ValueFromPipeline: false
  ValueFromPipelineByPropertyName: false
  ValueFromRemainingArguments: false
DontShow: false
AcceptedValues: []
HelpMessage: ''

-WhatIf

Runs the command in a mode that only reports what would happen without performing the actions.

Type: System.Management.Automation.SwitchParameter
DefaultValue: ''
SupportsWildcards: false
Aliases:
- wi
ParameterSets:
- Name: (All)
  Position: Named
  IsRequired: false
  ValueFromPipeline: false
  ValueFromPipelineByPropertyName: false
  ValueFromRemainingArguments: false
DontShow: false
AcceptedValues: []
HelpMessage: ''

CommonParameters

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

INPUTS

Objects with properties named like the path parameters can be piped to this function

{{ Fill in the Description }}

System.String

{{ Fill in the Description }}

OUTPUTS

The response of the GitHub API (objects

{{ Fill in the Description }}

NOTES

OperationId: git/create-tree Category: git / trees