在Git仓库中更改分支名称

时间:2021-04-11 23:42:59

How do I rename an existing branch in a Git repo?

如何重命名Git仓库中的现有分支?

I want the current branch to have a new name.

我希望当前分支有一个新名称。

2 个解决方案

#1


419  

Assuming you're currently on the branch you want to rename:

假设您当前在分支上,则要重命名:

git branch -m newname

This is documented in the manual for git-branch, which you can view using

这在git-branch手册中有记录,您可以使用它查看

man git-branch

or

要么

git help branch

Specifically, the command is

具体来说,命令是

git branch (-m | -M) [<oldbranch>] <newbranch>

where the parameters are:

参数是:

   <oldbranch>
       The name of an existing branch to rename.

   <newbranch>
       The new name for an existing branch. The same restrictions as for <branchname> apply.

<oldbranch> is optional, if you want to rename the current branch.

如果要重命名当前分支, 是可选的。

#2


114  

If you're currently on the branch you want to rename:

如果您当前在分支机构上,则要重命名:

git branch -m new_name 

Or else:

要不然:

git branch -m old_name new_name 

You can check with:

您可以查看:

git branch -a

As you can see, only the local name changed Now, to change the name also in the remote you must do:

如您所见,只有本地名称更改为Now,要更改遥控器中的名称,您必须执行以下操作:

git push origin :old_name

This removes the branch, then upload it with the new name:

这将删除分支,然后使用新名称上传它:

git push origin new_name

Source: https://web.archive.org/web/20150929104013/http://blog.changecong.com:80/2012/10/rename-a-remote-branch-on-github

资料来源:https://web.archive.org/web/20150929104013/http://blog.changecong.com:80/2012/10/rename-a-remote-branch-on-github

#1


419  

Assuming you're currently on the branch you want to rename:

假设您当前在分支上,则要重命名:

git branch -m newname

This is documented in the manual for git-branch, which you can view using

这在git-branch手册中有记录,您可以使用它查看

man git-branch

or

要么

git help branch

Specifically, the command is

具体来说,命令是

git branch (-m | -M) [<oldbranch>] <newbranch>

where the parameters are:

参数是:

   <oldbranch>
       The name of an existing branch to rename.

   <newbranch>
       The new name for an existing branch. The same restrictions as for <branchname> apply.

<oldbranch> is optional, if you want to rename the current branch.

如果要重命名当前分支, 是可选的。

#2


114  

If you're currently on the branch you want to rename:

如果您当前在分支机构上,则要重命名:

git branch -m new_name 

Or else:

要不然:

git branch -m old_name new_name 

You can check with:

您可以查看:

git branch -a

As you can see, only the local name changed Now, to change the name also in the remote you must do:

如您所见,只有本地名称更改为Now,要更改遥控器中的名称,您必须执行以下操作:

git push origin :old_name

This removes the branch, then upload it with the new name:

这将删除分支,然后使用新名称上传它:

git push origin new_name

Source: https://web.archive.org/web/20150929104013/http://blog.changecong.com:80/2012/10/rename-a-remote-branch-on-github

资料来源:https://web.archive.org/web/20150929104013/http://blog.changecong.com:80/2012/10/rename-a-remote-branch-on-github