Skip to content

Update‑GitLocalBranch

viscalyxbot edited this page Sep 30, 2025 · 1 revision

SYNOPSIS

Updates the specified Git branch by pulling or rebasing from the upstream branch.

SYNTAX

Default (Default)

Update-GitLocalBranch [-BranchName <String>] [-UpstreamBranchName <String>] [-RemoteName <String>] [-Rebase]
 [-ReturnToCurrentBranch] [-OnlyUpdateRemoteTrackingBranch] [-Force] 
 [-WhatIf] [-Confirm] [<CommonParameters>]

Default_UseExistingTrackingBranch

Update-GitLocalBranch [-BranchName <String>] [-UpstreamBranchName <String>] [-RemoteName <String>] [-Rebase]
 [-ReturnToCurrentBranch] [-UseExistingTrackingBranch] [-Force] [-WhatIf]
 [-Confirm] [<CommonParameters>]

Default_SkipSwitchingBranch

Update-GitLocalBranch [-BranchName <String>] [-UpstreamBranchName <String>] [-RemoteName <String>] [-Rebase]
 [-SkipSwitchingBranch] [-OnlyUpdateRemoteTrackingBranch] [-Force] 
 [-WhatIf] [-Confirm] [<CommonParameters>]

DESCRIPTION

This function checks out the specified local branch and either pulls the latest changes or rebases it with the upstream branch.

EXAMPLES

EXAMPLE 1

Update-GitLocalBranch

Checks out the 'main' branch and pulls the latest changes.

EXAMPLE 2

Update-GitLocalBranch -BranchName 'feature-branch'

Checks out the 'feature-branch' and pulls the latest changes.

EXAMPLE 3

Update-GitLocalBranch -BranchName 'feature-branch' -UpstreamBranchName 'develop' -Rebase

Checks out the 'feature-branch' and rebases it with the 'develop' branch.

EXAMPLE 4

Update-GitLocalBranch -BranchName 'feature-branch' -RemoteName 'upstream'

Checks out the 'feature-branch' and pulls the latest changes from the 'upstream' remote.

EXAMPLE 5

Update-GitLocalBranch -BranchName .

Pulls the latest changes into the current branch.

EXAMPLE 6

Update-GitLocalBranch -ReturnToCurrentBranch

Checks out the 'main' branch, pulls the latest changes, and switches back to the original branch.

PARAMETERS

-BranchName

Specifies the local branch name. Default is 'main'.

Type: String
Parameter Sets: (All)
Aliases:

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

-Force

If specified, the command will not prompt for confirmation.

Type: SwitchParameter
Parameter Sets: (All)
Aliases:

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

-OnlyUpdateRemoteTrackingBranch

If specified, only the remote tracking branch will be updated.

Type: SwitchParameter
Parameter Sets: Default, Default_SkipSwitchingBranch
Aliases:

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

-Rebase

Specifies that the local branch should be rebased with the upstream branch.

Type: SwitchParameter
Parameter Sets: (All)
Aliases:

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

-RemoteName

Specifies the remote name. Default is 'origin'.

Type: String
Parameter Sets: (All)
Aliases:

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

-ReturnToCurrentBranch

If specified, switches back to the original branch after performing the pull or rebase.

Type: SwitchParameter
Parameter Sets: Default, Default_UseExistingTrackingBranch
Aliases:

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

-SkipSwitchingBranch

If specified, the function will not switch to the specified branch.

Type: SwitchParameter
Parameter Sets: Default_SkipSwitchingBranch
Aliases:

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

-UpstreamBranchName

Specifies the upstream branch name. If not specified the value in BranchName will be used.

Type: String
Parameter Sets: (All)
Aliases:

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

-UseExistingTrackingBranch

If specified, only the existing tracking branch will be used to update the local branch.

Type: SwitchParameter
Parameter Sets: Default_UseExistingTrackingBranch
Aliases:

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

-Confirm

Prompts you for confirmation before running the cmdlet.

Type: SwitchParameter
Parameter Sets: (All)
Aliases: cf

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

-WhatIf

Shows what would happen if the cmdlet runs. The cmdlet is not run.

Type: SwitchParameter
Parameter Sets: (All)
Aliases: wi

Required: False
Position: Named
Default value: None
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

None

This function does not return any output.

NOTES

This function requires Git to be installed and accessible from the command line. The function will check for unstaged or staged changes before proceeding.

RELATED LINKS

Clone this wiki locally