git重命名分支

git重命名分支教程

git 中,我们要重命名当前的分支,可以使用 git branch 命令。

git重命名分支详解

语法

git branch -m oldBranchName newBranchName

参数

参数 描述
oldBranchName 旧分支名。
newBranchName 新分支名。

git重命名远程分支详解

语法

git branch -m oldBranchName newBranchName # 将本地的分支进行重命名 git push origin newBranchName # 将新的分支推送到远程 git push --delete origin oldBranchName # 删除远程的旧的分支

参数

参数 描述
oldBranchName 旧分支名。
newBranchName 新分支名。

说明

我们首先,使用 git branch -m 命令,将 oldBranchName 分支重命名为 newBranchName,接着,我们使用了 git push 将 newBranchName 推送到远程,最后,使用 git push --delete 删除远程的 oldBranchName 分支。

Git重命名分支

语法

git branch -m oldBranchName newBranchName

案例

我们首先,使用 git branch 命令,创建一个 test 分支,具体命令如下:

git branch test

执行完毕后,如下图所示:

11_git重命名分支.png

现在,我们使用 git branch -m 重命名该分支,具体命令如下:

git branch -m test new_test

执行完毕后,如下图所示:

12_git重命名分支.png

我们看到,我们已经将 test 分支重命名为了 new_test 分支,现在,我们使用 git branch 命令,查看分支,具体命令如下:

git branch

执行完毕后,如下图所示:

13_git重命名分支.png

我们看到,此时 new_test 分支已经存在了。

git重命名分支总结

在 git 中,我们要重命名当前的分支,可以使用 git branch 命令。