簡體   English   中英

如何用git覆蓋不同本地分支的遠程分支

[英]How to overwrite remote branch with different local branch with git

我有一個遠程分支,是pullrequest的基礎。

我主要在不同的分支上工作,但現在應該替換舊的分支。

我試圖做一個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

您可以對git push使用local-name:remote-name語法:

git push origin newBranch:oldBranch

這會推動newBranch ,但在源上使用名稱oldBranch

因為oldBranch可能已經存在,所以你必須強制它:

git push origin +newBranch:oldBranch

(我更喜歡+而不是-f ,但-f也會起作用)

要刪除遠程端的分支,請按下“空分支”,如下所示:

git push origin :deleteMe

來自: https//deltacloud.apache.org/send-pull-request.html

 $ git checkout -b my branch
  Coding your changes
 $ git commit -m "Commit message"

推動你的工作

更新原始倉庫這將避免可能的合並沖突和應用修補程序的問題。

$ git checkout master
$ git pull

推到你的前叉。

 $ git checkout my_work_topic
 $ git rebase -i master (Tip: You can rename/squash commits at this point)
 $ git push origin my_work_topic

發出Pull請求

導航到您的分叉Github存儲庫例如: https//github.com/your username / deltacloud-core.git單擊Pull Request選項卡(提示:您可以使用hub自動執行此步驟)有關使用pull請求的更多詳細信息,請參閱: 使用Pull請求的官方GitHub幫助

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM