Git:如何使用多个存储库? [英] Git: how to work with multiple repositories?

查看:61
本文介绍了Git:如何使用多个存储库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个远程只读git存储库 A ,已将其克隆到本地文件系统中. A 会定期更新,每次更新后,我都会在系统中提取并合并更新的代码.

我想与团队成员合作处理 A 的文件,为此,我创建了一个新的远程存储库 B .

我如何设法将 B 与本地存储库同步?我想学习正确的命令顺序和配置选项以实现我的目标.以下是我希望能够解决的方案:1.进行更新后,从A中拉出,然后将其推入B中.2.从A拉出,将其与我的本地文件合并,然后将其推到B,与B上的存储库合并.3.我希望所有A,我的本地仓库和B都具有相同的分支.

感谢您的帮助.如果我的问题不太清楚,请提及它,我将尝试对其进行编辑.谢谢.

解决方案

我假设您有两个名为A和B的遥控器,它们仅配置了URL.如果您不遵循参考规范,请阅读ProGit书中的相关章节.

1:有更新后从A拉出,然后将其推入B

  $#pull =提取+(通常是快进合并)$ git fetch A#从A获取所有对象(所有分支,提交;所有内容)$ git push B'refs/remotes/A/*:refs/heads/*'$#我已引用,以便外壳程序不尝试扩展* 

编辑:我假设您不想将更改合并到本地分支中.

2:从A提取,与我的本地文件合并,然后将其推到B,再与B上的存储库合并.

  $ git pull A#获取+尝试合并所有分支中的更改$#解决任何冲突$ git push B'+ refs/heads/*:refs/heads/*'#如果是FF推,则省略+$#默认是推送匹配的分支 

编辑:上面的操作不会合并B中的更改.如果要执行此操作,则还必须从B中提取更改,然后将其合并到本地分支中,然后再进行推送./p>

3:我希望A,本地仓库和B的所有分支都具有相同的分支

  $ git pull A$ git checkout branchx$ git reset --hard A/branchx#警告!所有本地更改将被销毁$#对所有分支重复以上操作$ git push B'+ refs/heads/*:refs/heads/*'#警告!B中的数据被覆盖 

编辑:如果您要删除过时的跟踪分支,请运行

  $ git remote prune A$ git remote prune B 

I have a remote read-only git repository A, which I have cloned in my local filesystem. A is updated periodically, and I pull and merge the updated code in my system after each update.

I want to collaborate with my team members on the files of A, for which, I have create a new remote repository B.

How do I manage to sync B with my local repository? I would like to learn the proper command sequence and configuration options to achieve my goals. Here are the scenarios I would like to be able to solve: 1. Pull from A after there are updates, push it to B. 2. Pull from A, merge it with my local files, then push it to B, merging with the repo on B. 3. I would like all of A, my local repo and B to have identical branches.

I would be thankful for any help. If my question is not very clear, please mention it, and I will try to edit it. Thanks.

解决方案

I'm assuming that you have two remotes named A and B that have just the url configured. If you don't follow the refspecs, read the relevant chapter in the ProGit book.

1: Pull from A after there are updates, push it to 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 *

EDIT: I've assumed that you do not want to merge changes into your local branches.

2: Pull from A, merge it with my local files, then push it to B, merging with the repo on B.

$ 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

EDIT: The above doesn't merge the changes in B. If you'd like to do that, you must pull changes from B also and merge them into your local branches before pushing.

3: I would like all of A, my local repo and B to have identical branches

$ 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

EDIT: If you'd like to remove stale tracking branches, run

$ git remote prune A
$ git remote prune B

这篇关于Git:如何使用多个存储库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆