gpt4 book ai didi

git - 如何用git用不同的本地分支覆盖远程分支

转载 作者:IT王子 更新时间:2023-10-29 00:34:28 25 4
gpt4 key购买 nike

我有一个远程分支,它是 pull 请求的基础。

我主要在不同的分支上工作,但是现在应该取代旧的分支。

我尝试执行 git push remote oldBranch -f 但这只会将我最新的本地 oldBranch 推送到 git 服务器而不是当前分支 - 无论哪个分支我现在在。

如何用本地分支替换远程分支?

编辑:如果其他人有兴趣,这就是我如何让它工作的:

git checkout oldBranch
git branch -m 'oldBranchToBeReplaced'
git checkout newBranch
git branch -m oldBranch
git push myrepo oldBranch -f

最佳答案

您可以使用 local-name:remote-name 语法进行 git push:

git push origin newBranch:oldBranch

这会推送 newBranch,但在 origin 上使用名称 oldBranch

因为 oldBranch 可能已经存在,所以你必须强制它:

git push origin +newBranch:oldBranch

(我更喜欢 + 而不是 -f,但是 -f 也可以)

要删除远程端的分支,像这样推送一个“空分支”:

git push origin :deleteMe

关于git - 如何用git用不同的本地分支覆盖远程分支,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39389380/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com