如何安全地推送到本地git存储库?
问题描述:
我们有两个git软件库a
和b
。两者都是本地存储库。我如何推回购b
回购a
和回购a
回购b
?如何安全地推送到本地git存储库?
# remove and create new '/tmp/repos'
rm -rf /tmp/repos
mkdir -p /tmp/repos
# create (init) and config repo 'a'
git init /tmp/repos/a
git -C /tmp/repos/a config user.email "[email protected]"
git -C /tmp/repos/a config user.name "name_a"
# clone and config repo 'a' to repo 'b'
git clone /tmp/repos/a /tmp/repos/b
git -C /tmp/repos/b config user.email "[email protected]"
git -C /tmp/repos/b config user.name "name_b"
# create file './text.txt' in repo 'b', add it, and commit it
echo "first line" > /tmp/repos/b/test.txt
git -C /tmp/repos/b add ./test.txt
git -C /tmp/repos/b commit ./test.txt -m "add first line"
我到目前为止已经试过是设置a
为纯仓库,从推到b
a
,并重置a
到非纯仓库:
git -C /tmp/repos/a config --bool core.bare true
git -C /tmp/repos/b push origin master
git -C /tmp/repos/a config --bool core.bare false
但这不是一个解决方案,因为这两个存储库必须有一个工作目录,我们不能依赖于其他存储库的状态。
请注意,我希望从回购b
推回购买a
(或类似的东西)。我知道我可以从回购a
拉回购b
。但这是而不是我所需要的。
git -C /tmp/repos/a pull /tmp/repos/b
顺便说一句,目前我们正在使用中间本地回购c
。 我们正在寻找一种方法来避免这样的第三个(公共)存储库。 没有*存储库的实际分布类型。 我知道使用公共存储库是安全,健壮和简单的。 我感兴趣的是了解它如何在没有它的情况下工作, 并了解两个存储库与工作树直接通信时的问题所在。换句话说:如果它不安全,健壮和简单,我想真正明白为什么。
答
如果我理解正确的话,您可以选择本地2个回购其(简化)看起来是这样的:
a
|- .git
|- foo.txt
和
b
|- .git
|- bar.txt
现在你想从回购一推,回购乙?这是不寻常的设置,因为一般情况下,您不推动工作回购,而是远程回购。因此,在这种情况下,您将创建3日回购:
mkdir c.git && cd c && git init --bare
你会使用回购作为您“远程”:
git remote add origin /path/to/c.git
然后你就可以使用它与任何其他远程回购。
但如果你真的要推到工作回购,那么你需要推到.git
文件夹,因此您的命令看起来像:
git push /path/to/b/.git master
但是请记住,这只会更新的Git目录和工作树会保持不动,直到有人来做git checkout master
。
你的意思是像git submodule的东西? https://git-scm.com/book/en/v2/Git-Tools-Submodules – McLemore
你想做什么?为什么这两个存储库必须有一个工作树?你应该考虑让他们彼此相处吗? – eis
@McLemore:不完全。 AFIK子模块不打算以对称方式工作。即A作为B和B的子模块作为A的子模块。 – wolfrevo