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

How to change the name of a git branch

WBOY
Release: 2022-01-14 15:33:30
Original
39014 people have browsed it

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
Copy after login
Copy after login

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
Copy after login
Copy after login

b. Delete the remote branch

git push --delete origin oldName
Copy after login

c. Upload the newly named local branch

git push origin newName
Copy after login

d. Put the modified local branch Associated with remote branches

git branch --set-upstream-to origin/newName
Copy after login

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!

Related labels:
git
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template