在 git 中,我们要重命名当前的分支,可以使用 git branch 命令。
git branch -m oldBranchName newBranchName
参数 | 描述 |
---|---|
oldBranchName | 旧分支名。 |
newBranchName | 新分支名。 |
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 branch -m oldBranchName newBranchName
我们首先,使用 git branch 命令,创建一个 test 分支,具体命令如下:
git branch test
执行完毕后,如下图所示:
现在,我们使用 git branch -m 重命名该分支,具体命令如下:
git branch -m test new_test
执行完毕后,如下图所示:
我们看到,我们已经将 test 分支重命名为了 new_test 分支,现在,我们使用 git branch 命令,查看分支,具体命令如下:
git branch
执行完毕后,如下图所示:
我们看到,此时 new_test 分支已经存在了。
在 git 中,我们要重命名当前的分支,可以使用 git branch 命令。