-
Notifications
You must be signed in to change notification settings - Fork 1
Rename‑GitLocalBranch
Renames a local Git branch and optionally updates remote tracking and default branch settings.
Rename-GitLocalBranch [-Name] <String> [-NewName] <String> [[-RemoteName] <String>] [-SetDefault]
[-TrackUpstream] [-Force] [-WhatIf] [-Confirm] [<CommonParameters>]
This function renames a local Git branch. It can also update the upstream tracking and set the new branch as the default for the remote repository.
This function supports ShouldProcess functionality for safe operations and includes a Force parameter to bypass confirmation prompts.
Rename-GitLocalBranch -Name "feature/old-name" -NewName "feature/new-name"
This example renames a local branch from "feature/old-name" to "feature/new-name". It does not affect any remote settings.
Rename-GitLocalBranch -Name "develop" -NewName "main" -TrackUpstream -SetDefault
This example renames the local "develop" branch to "main", sets up upstream tracking for the new branch, and sets it as the default branch for the remote repository. This is useful when standardizing branch names across projects.
Rename-GitLocalBranch -Name "bugfix/issue-123" -NewName "hotfix/critical-fix" -RemoteName "upstream" -TrackUpstream
This example renames a branch from "bugfix/issue-123" to "hotfix/critical-fix", sets up tracking with a remote named "upstream", but does not change the default branch.
Rename-GitLocalBranch -Name "feature/old-name" -NewName "feature/new-name" -Force
This example renames a branch with the Force parameter, bypassing confirmation prompts when used with -Confirm:$false.
Forces the operation to proceed without confirmation prompts, similar to -Confirm:$false.
Type: SwitchParameter
Parameter Sets: (All)
Aliases:
Required: False
Position: Named
Default value: False
Accept pipeline input: False
Accept wildcard characters: FalseThe current name of the branch to be renamed.
Type: String
Parameter Sets: (All)
Aliases:
Required: True
Position: 1
Default value: None
Accept pipeline input: False
Accept wildcard characters: FalseThe new name for the branch.
Type: String
Parameter Sets: (All)
Aliases:
Required: True
Position: 2
Default value: None
Accept pipeline input: False
Accept wildcard characters: FalseThe name of the remote repository. Defaults to 'origin'.
Type: String
Parameter Sets: (All)
Aliases:
Required: False
Position: 3
Default value: Origin
Accept pipeline input: False
Accept wildcard characters: FalseIf specified, sets the newly renamed branch as the default branch for the remote repository.
Type: SwitchParameter
Parameter Sets: (All)
Aliases:
Required: False
Position: Named
Default value: False
Accept pipeline input: False
Accept wildcard characters: FalseIf specified, sets up the newly renamed branch to track the upstream branch.
Type: SwitchParameter
Parameter Sets: (All)
Aliases:
Required: False
Position: Named
Default value: False
Accept pipeline input: False
Accept wildcard characters: FalsePrompts 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: FalseShows 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: FalseThis cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters.
This function requires Git to be installed and accessible in the system PATH.
- Assert-GitLocalChange
- Assert-GitRemote
- Assert-IPv4Address
- Clear-AnsiSequence
- ConvertTo-AnsiSequence
- ConvertTo-AnsiString
- ConvertTo-DifferenceString
- ConvertTo-RelativePath
- Disable-CursorShortcutCode
- Get-ClassAst
- Get-ClassResourceAst
- Get-GitBranchCommit
- Get-GitLocalBranchName
- Get-GitRemote
- Get-GitRemoteBranch
- Get-GitTag
- Get-LinkLayerAddress
- Get-ModuleByVersion
- Get-ModuleFileSha
- Get-ModuleVersion
- Get-NumericalSequence
- Get-PSReadLineHistory
- Get-TextOffset
- Install-ModulePatch
- Invoke-Git
- Invoke-PesterJob
- New-GitTag
- New-SamplerGitHubReleaseTag
- Out-Difference
- Pop-VMLatestSnapshot
- Push-GitTag
- Receive-GitBranch
- Remove-GitTag
- Remove-History
- Remove-PSHistory
- Remove-PSReadLineHistory
- Rename-GitLocalBranch
- Rename-GitRemote
- Request-GitTag
- Resolve-DnsName
- Resume-GitRebase
- Send-WakeOnLan
- Split-StringAtIndex
- Start-GitRebase
- Stop-GitRebase
- Switch-GitLocalBranch
- Test-FileHash
- Test-GitLocalChanges
- Test-GitRemote
- Test-GitRemoteBranch
- Test-IPv4Address
- Update-GitLocalBranch
- Update-RemoteTrackingBranch