我有一个本地分支主指向一个远程分支原点/regacy(哎呀,拼写错误!)
如何将远程分支重命名为原点/遗留或原点/主?
我试着:
git remote rename regacy legacy
但这给出了一个错误:
错误:不能重命名配置区段的远程。Regacy '到'remote.legacy'
我有一个本地分支主指向一个远程分支原点/regacy(哎呀,拼写错误!)
如何将远程分支重命名为原点/遗留或原点/主?
我试着:
git remote rename regacy legacy
但这给出了一个错误:
错误:不能重命名配置区段的远程。Regacy '到'remote.legacy'
当前回答
另一个解决方法如下:
签出到您想更改的分支 从它创建一个新分支 上游设置为远程 从本地和远程删除旧的分支
更具体地说:
# Checkout to the branch you want to rename
git checkout <old_branch_name>
# Create a new branch from the old one and checkout to it
git checkout -b <new_branch_name>
# Push the new branch to remote
git push -u <origin> HEAD
# Delete local branch
git branch -d <old_branch_name>
# Delete remote branch
git push <origin> -d <old_branch_name>
其他回答
检查您正在使用下面的命令的分支
git branch -a
签出到要重命名的分支
git checkout branch_to_rename
使用以下命令重命名分支
git branch -m new_name
推动改变
git push origin :old_name new_name
我使用这些git别名,它几乎自动完成工作:
git config --global alias.move '!git checkout master; git branch -m $1 $2; git status; git push --delete origin $1; git status; git push -u origin $2; git branch -a; exit;'
用法:git从_branch移动到_branch
如果你有默认的名称,如master, origin等,它就可以工作。 你可以根据自己的意愿进行修改,但这只是个概念。
托管在GitHub上的Git存储库中的分支可以使用存储库设置重命名。作为一个副作用,GitHub中的分支保护规则也将被改变。
访问存储库设置中的“分支”:https://github.com/<name>/<repository-name>/settings/ Branches 重命名分支 每个使用这个存储库的人都必须在本地做:
$ git获取 $ git checkout <new_name>
这甚至可以在不重命名本地分支的情况下完成,只需简单的三个步骤:
去你的GitHub仓库 从要重命名的旧分支创建一个新分支 删除旧的分支
如果你想用一个命令重命名当前分支,就像这样:
git rename my-new-branch-name
然后,你必须创建一个名为git-rename的文件,使其可执行(chmod +x git-rename),并将其保存到你的$PATH文件夹中,包含以下内容:
#!/bin/sh
currentBranch="$(git rev-parse --abbrev-ref HEAD)"
test $# != 1 && cat <<EOF && exit 1
Renames the current branch ($currentBranch) both locally and remotely.
USAGE:
git rename <new branch name>
EOF
newBranch="$1"; shift
git branch -m "$newBranch" && \
git push origin :"$currentBranch" "$newBranch"