git - 可以重命名分支吗?

标签 git gitlab

我在 git 上工作了一段时间(使用 gitlab.com)。
现在我明白了,最好为已用分支使用另一个名称。

是否可以更改该分支名称 - 即使它有多个提交并且过去已经 merge 到另一个分支 - 本地和远程?

因为它是一个“旧”分支,已经被 merge 了,所以我不能建立一个新分支并删除旧分支。

最佳答案

Is it possible to change that branch name

# use the -m flag for move
git branch -m <oldname> <newname>

# now you have to push the new branch to the server
git push origin <newname>

# delete the old remote branch
git push origin --delete <oldname>

Because it is a 'old' branch, which has already being merged, I can't build a new one and delete the old one.

如果您的分支已 merge 并且您不再需要它,您可以在本地删除它:

git branch -D <oldname>

关于git - 可以重命名分支吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36111306/

相关文章:

docker - 自定义Docker桥接网络

java - 将android项目添加到git

git - 复制文件时 Homebrew 安装失败

ios - XCode (git) 提交文件失败

docker - 如何让 Docker 中的 GitLab Runner 看到自定义 CA 根证书

gitlab - 有没有办法动态选择作业是否在 Gitlab CI 管道中运行?

Eclipse git 推送所有分支而不是仅推送当前分支

git - fork 后如何从父 Git 存储库中提取更新?

variables - 如何将值从提交传递到 GitLab CI 管道作为变量?

maven - 如何为 docker shell gitlab runner 安装 maven