这是场景。我有两台机器,“桌面”和“笔记本电脑”。如何让两个git存储库保持同步?
在桌面上我做的:
mkdir git_test
cd git_test
git init
dd if=/dev/urandom of=test.img bs=1k count=1000
git add test.img
git commit -m "Added first image"
然后在笔记本电脑,我做的事:
git clone [USER]@desktop:/home/[USER]/git_test
cd git_test
dd if=/dev/urandom of=test2.img bs=1k count=1000
git add test2.img
git commit -m "Added second image"
然后我想我的桌面上的混帐回购协议看起来像我的笔记本电脑的混帐回购协议。在笔记本电脑上,我发出以下命令: 混帐推起源主
但后来我得到:
remote: error: refusing to update checked out branch: refs/heads/master
remote: error: By default, updating the current branch in a non-bare repository
remote: error: is denied, because it will make the index and work tree inconsistent
remote: error: with what you pushed, and will require 'git reset --hard' to match
remote: error: the work tree to HEAD.
remote: error:
remote: error: You can set 'receive.denyCurrentBranch' configuration variable to
remote: error: 'ignore' or 'warn' in the remote repository to allow pushing into
remote: error: its current branch; however, this is not recommended unless you
remote: error: arranged to update its work tree to match what you pushed in some
remote: error: other way.
remote: error:
remote: error: To squelch this message and still keep the default behaviour, set
remote: error: 'receive.denyCurrentBranch' configuration variable to 'refuse'.
如何保持这两个回购同步?
错误消息似乎暗示git有我想要的功能,但出于某种原因,它似乎是一个更高级的工作流程。我听到有人曾经说过,你不能推到你现在所在的分支,有人能说这是一个可能的解决方案吗?我对这种性质的解决方案没有任何问题,例如,我可以在我的笔记本电脑上的某个分支上工作,并在我的桌面上处理另一个分支上的问题,然后以某种方式同步它们,使它们完全相同。
请注意以下事项!
我不想使用集中式回购,像github上,有几个原因。首先是安全。第二个是简单。第三是由于情况我不会进入这里,我不能指望有一个互联网连接到一些远程服务器,我只有我的两台机器通过局域网连接。最后,我想学习如何按照我在这里所要求的方式来做事,以获得特定的知识。
我也不想使用裸回购,因为裸回购在根目录中有一堆垃圾。这是丑陋和混乱。我从颠覆转向git的全部原因是,git看起来像是一个更清洁,分散的解决方案。另外,我还有一些非技术人员会在桌面的根目录中工作,他们会被这个问题困惑不解。 git的美妙之处在于(我认为)所有东西隐藏在.git文件夹中。编辑:显然,我不清楚这一点。想象一下,我有一个“Documents”文件夹,其中包含以下子文件夹:mydata1和mydata2。这不是一个人为的例子,这正是我想要处理的问题。 mydata1应该包含“test.img”,只有这个文件,而是它现在有:
分支 配置 描述 HEAD 钩 信息 对象 裁判
我希望能够只需cd到mydata1并开始编辑文件,但是我必须尝试通过分支机构cd,或者甚至只是为了完成工作。并且对于这种类型的目录结构,每个子文件夹在“文档”中是不可行的。请不要告诉我这样做。请回答这个问题。谢谢。
这两点是整个原因我在这里发布这个问题。请只回答如果你有这个问题的答案。 :) 谢谢!!
我指的是“cruft”,如下所示:“分支配置说明HEAD挂钩信息对象引用”我只想/ home/[User]/git_repo只包含我正在使用的文件。另外:.git文件夹被隐藏。 –
您可以隐藏回购。 – nobar