我如何重命名尚未被推到远程仓库的本地分支 ?
相关:
当前回答
如果您在分支上, 您想要重命名 :
git branch -m new-name
如果在另一分支上:
git branch -m old-name new-name
git push origin :old-name new-name
git push origin -u new-name
或者为了快速地做到这一点 你可以使用这三步:
# 本地重命名分支
git branch -m old_branch new_branch
# 删除旧的远程分支
git push origin :old_branch
# 推动新分支, 设置本地分支以跟踪新远程
git push --set-upstream origin new_branch
参考:https://www.w3docs.com/snippets/git/how-to-rename-git-local-and-remote-branches.html
其他回答
要重命名您的当前分支 :
git branch -m <newname>
试图具体回答问题(至少是标题)。
您也可以重新命名当地当地树枝,但继续追踪遥控器上的旧名称。
git branch -m old_branch new_branch
git push --set-upstream origin new_branch:old_branch
现在,当你跑的时候git push
远程old_branch
ref 与您的本地更新new_branch
.
你必须知道并记住配置此配置。 但如果您没有选择远程分支名称的选择, 它可能会有用, 但是您不喜欢它( 我的意思是, 您有一个非常好也希望本地分行名称更明确。
使用抓取配置, 您甚至可以重命名本地远程引用 , 即refs/remote/origin/new_branch
ref 指向分支,事实上就是old_branch
上 年 月origin
然而,我非常不赞成这样做,因为你心智安全。
Git 分支重命名可以使用 :
git branch -m oldBranch newBranch
git branch -M oldBranch ExistingBranch
和(或)- 中 - 中和- MM,MM,MM,MM,MM,M:
- 毫米:如果您试图用现有的分支名称重命名您的分支- 中 - 中。它会引出一个错误,表示分支已经存在。您需要给出独有的名称。
但是,
- 男: - 男: - 女: - M:这将帮助您强制重命名一个指定的名称, 即使它已经存在 。 因此一个已有的分支将完全覆盖它...
这儿有一个吉特终点的例子,
mohideen@dev:~/project/myapp/sunithamakeup$ git branch
master
master0
new_master
test
* test1
mohideen@dev:~/project/myapp/sunithamakeup$ git branch -m test1 test
fatal: A branch named 'test' already exists.
mohideen@dev:~/project/myapp/sunithamakeup$ git branch -M test1 test
mohideen@dev:~/project/myapp/sunithamakeup$ git branch
master
master0
new_master
* test
mohideen@dev:~/project/myapp/sunithamakeup$
吉特・伊特的反派命令 试试这个 对我有用
默认分支已被重新命名 ! { oldBranchName} 现在命名为{ newBranchName} 如果您有本地克隆, 您可以运行以下命令来更新它 。
git branch -m {oldBranchName} {NewBranchName}
git fetch origin
git branch -u origin/{NewBranchName} {NewBranchName}
git remote set-head origin -a
高级 Git 用户可以手动重命名 :
Rename the old branch under .git/refs/heads to the new name
Rename the old branch under .git/logs/refs/heads to the new name
Update the .git/HEAD to point to yout new branch name