Home  >  Article  >  Development Tools  >  How to change the name of a git branch

How to change the name of a git branch

WBOY
WBOYOriginal
2022-01-14 15:32:4738949browse

Method: 1. Use the branch operation to modify the local branch name. The syntax is "git branch -m old name new name"; 2. After deleting the remote branch, use the "git push origin new name" command to modify the remote branch name. .

How to change the name of a git branch

The operating environment of this article: Windows 10 system, Git version 2.30.0, Dell G3 computer.

How to change the name of a git branch

Assume the branch name is oldName

I want to change it to newName

1. Rename the local branch (not yet pushed to the remote)

git branch -m oldName newName

2. Rename the remote branch (already pushed to the remote - assuming the names of the local branch and the remote corresponding branch are the same)

a. Rename the local branch corresponding to the remote branch

git branch -m oldName newName

b. Delete the remote branch

git push --delete origin oldName

c. Upload the newly named local branch

git push origin newName

d. Put the modified local branch Associated with remote branches

git branch --set-upstream-to origin/newName

Recommended learning: "Git Tutorial"

The above is the detailed content of How to change the name of a git branch. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn