乐闻世界logo
搜索文章和话题

How do i rename both a git local and remote branch name?

2个答案

1
2

If you mistakenly named a branch and pushed it to the remote repository, follow these steps to rename it.

  1. Renaming your local branch:
    • If you are on the branch you want to rename:
      bash
      git branch -m new-name
    • If you are on a different branch:
      bash
      git branch -m old-name new-name
  2. Delete the remote branch old-name and push the local branch new-name: git push origin :old-name new-name
  3. Reset the upstream branch for the newly named local branch:
    • Switch to the branch, then: git push origin -u new-name
2024年6月29日 12:07 回复

List all branches

shell
git branch -a

Switch to the branch you want to rename

bash
git checkout branch_to_rename

Rename the branch

bash
git branch -m new_name

Push the changes to update the remote branch name

bash
git push origin :old_name new_name
2024年6月29日 12:07 回复

你的答案