[英]How to pull from one remote branch to another branch in git?
出於安全原因,我的主管不允許我直接從主分支機構提取他的工作。 所以我創建了一個遠程命名為“subbranch”的分支,並將其克隆到我的本地存儲庫。 我怎么能讓'subbranch'與主分支保持同步? 我只知道如何使用GUI來做到這一點。 如何用命令行完成?
如果尚未完成,則已從master中克隆存儲庫,然后在克隆中創建本地分支,並跟蹤到上游分支。 例如
git clone https://github.com/rgulia/myclone
cd myclone
git checkout -b subbranch origin/subbranch
當您需要在克隆中工作時,請確保您在分支機構中。
git branch # your current branch is highlighted with a '*'
通常,通過對您的分支進行更改來在您的分支上工作。 將更改推送到遠程分支。
git commit
git push origin subbranch
您有時希望使用master中的更改進行更新
git fetch # get the changes from the remote repository.
git merge master # merge them into your branch
git push origin subbranch # push your changes upstream
git fetch適用於所有分支,包括master。 git merge在您的分支中創建一個提交。 因為你總是在你的分支機構工作,所以你永遠不會提交或推動掌握。
您可能必須解決沖突。 看到這個優秀的教程。 http://www.vogella.com/tutorials/Git/article.html#mergeconflict
我希望這有幫助。
git branch --set-upstream-to remote-branch#用遠程分支跟蹤你的本地分支
git pull --rebase#來獲取遠程分支的最新變化
我假設兩個分支主和demo.Merge主代碼演示步驟1 A.go到master-> git checkout Master。 B.pull來自Master分支的所有新變化。 步驟2 A.現在進入演示分支 - > git checkout演示步驟3 A.將Master分支的更改導入演示分支git merge Master B.然后將更新的代碼推送到git git push origin演示
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.