问题描述
我有一个远程分支,这是pullrequest的基础.
I have a remote branch that is the basis for a pullrequest.
我主要在另一个分支上工作,但是现在应该替换旧的分支.
I mainly worked on a different branch, however that should now replace the old branch.
我试图做一个 git push remote oldBranch -f
,但这只会将我最新的本地 oldBranch
推送到git服务器,而不是当前分支-不管哪个分支我目前在.
I tried to do a git push remote oldBranch -f
but that only pushes my latest local oldBranch
to the git server instead of the current branch - no matter which branch i am currently on.
如何用本地分支替换远程分支?
How can I replace the remote branch with my local branch?
如果其他人有兴趣,这就是我让它起作用的方式:
If anybody else is interested, this is how i got this to work:
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:
You can use the local-name:remote-name
syntax for git push:
git push origin newBranch:oldBranch
这会推送 newBranch
,但在起点使用名称 oldBranch
.
This pushes newBranch
, but using the name oldBranch
on origin.
因为 oldBranch
可能已经存在,所以您必须强制执行此操作:
Because oldBranch
probably already exists, you have to force it:
git push origin +newBranch:oldBranch
(我更喜欢使用 +
而不是 -f
,但是 -f
也可以使用)
(I prefer the +
instead of -f
, but -f
will work, too)
要删除远端的分支,请按如下所示推动空分支":
To delete a branch on the remote side, push an "empty branch" like so:
git push origin :deleteMe
这篇关于如何使用git用不同的本地分支覆盖远程分支的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!