簡體   English   中英

Git:如何使用多個存儲庫?

[英]Git: how to work with multiple repositories?

我有一個遠程只讀git存儲庫A ,我已經在我的本地文件系統中克隆了它。 A會定期更新,每次更新后我都會在系統中提取並合並更新后的代碼。

我想與我的團隊成員就A的文件進行協作,為此,我創建了一個新的遠程存儲庫B

如何設置將B與本地存儲庫同步? 我想學習正確的命令序列和配置選項來實現我的目標。 以下是我希望能夠解決的方案:1。在有更新后從A拉出,將其推送到B. 2.從A中拉出,將其與我的本地文件合並,然后將其推送到B,與之合並回復B. 3.我希望所有的A,我的本地回購和B都有相同的分支。

我會感謝任何幫助。 如果我的問題不是很清楚,請提及,我會嘗試編輯它。 謝謝。

你可以試試

git clone repoB url ...
git remote add repoA url-to-repo-A
git pull repoA

1)

git pull repoA
git push repoB

2)

git pull repoA
git checkout local-branch-to-merge
git merge repoA / remote-branch-to-merge
git push repoB

3)我不確定是否有任何技巧可以通過一個命令檢查repoA上的所有分支到repoB或本地倉庫...如果沒有,你可以隨時手動執行

git checkout --track -b branch1 repoA / branch1

當你推,他們應該推到遠程相應的分支

我假設你有兩個名為A和B的遙控器,它們只配置了url。 如果您不遵循refspecs,請閱讀ProGit書中的相關章節

1:有更新后從A拉出,將其推到B.

$ # pull = fetch + (often fast-forward merge)
$ git fetch A # fetches all objects from A (all branches, commits; everything)
$ git push B 'refs/remotes/A/*:refs/heads/*'
$ # I've quoted so that the shell doesn't try to expand the *

編輯:我假設您不希望將更改合並到您的本地分支。

2:從A中拉出,將其與我的本地文件合並,然后將其推送到B,與B上的repo合並。

$ git pull A # fetch + attempt to merge changes in all branches
$ # Resolve any conflicts here
$ git push B '+refs/heads/*:refs/heads/*' # omit the + if it's a FF push
$ # Default is to push matching branches

編輯:上面沒有合並B中的更改。如果你想這樣做,你必須從B中提取更改並在推送之前將它們合並到本地分支。

3:我希望所有A,我的本地倉庫和B都有相同的分支

$ git pull A
$ git checkout branchx
$ git reset --hard A/branchx # Warning! All local changes will be destroyed
$ # Repeat the above for all branches
$ git push B '+refs/heads/*:refs/heads/*' # Warning! Data in B is overwritten

編輯:如果您想刪除陳舊的跟蹤分支,請運行

$ git remote prune A
$ git remote prune B

我建議在有B的主機上設置cronjob。 這樣,來自回購A更新被及時拉出(比如每小時兩次)。 你只需要從B拉出來。

暫無
暫無

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

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