LinuxCommandLibrary
GitHubF-DroidGoogle Play Store

git-rename-branch

Rename a Git branch locally and on the remote

TLDR

Rename current branch
$ git rename-branch [new_name]
copy
Rename specific branch
$ git rename-branch [old_name] [new_name]
copy

SYNOPSIS

git rename-branch [oldname] newname

DESCRIPTION

git rename-branch renames a branch both locally and on the remote. Part of git-extras, it handles the local rename, pushes the new branch name to the remote, deletes the old remote branch, and updates the upstream tracking reference in a single command.Without this tool, renaming a remote branch requires multiple steps: `git branch -m`, `git push origin newname`, `git push origin --delete oldname`, and `git branch -u origin/new_name`.

PARAMETERS

old_name

The current name of the branch to rename. If omitted, the current branch is used.
new_name
The new name for the branch.

CAVEATS

Requires git-extras to be installed. Other collaborators must update their local references after the rename. Pull requests or merge requests targeting the old branch name may need manual updates.

SEE ALSO

Copied to clipboard
Kai