这是场景.我有两台机器,"桌面"和"笔记本电脑".
在桌面上我做:
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"
Run Code Online (Sandbox Code Playgroud)
然后在笔记本电脑上我做:
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"
Run Code Online (Sandbox Code Playgroud)
然后我希望桌面上的git repo看起来像我笔记本电脑上的git repo.在笔记本电脑上,我发出以下内容:git push origin master
但后来我得到:
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'.
Run Code Online (Sandbox Code Playgroud)
如何保持这两个回购同步?
错误消息似乎暗示git具有我想要的功能,但由于某种原因,它似乎是一个更高级的工作流程.我听说有人说你不能推到你目前所在的分支机构,有人可以详细说明这个可能的解决方案吗?我对这种性质的解决方案没有任何问题,即我可以在我的笔记本电脑上的某个分支上工作,在我的桌面上使用不同的分支,然后以某种方式同步这些分支以使它们完全相同.
请注意以下事项!
出于几个原因,我不想像github那样使用集中式仓库.首先是安全.第二是简单.第三是由于我不会进入这里的情况,我不能指望有一个互联网连接到一些远程服务器,我只有我的两台机器通过局域网连接.最后,我想学习如何以我在这里要求的方式做事,以获得特定的知识.
我也不想使用裸仓库,因为一个裸仓库在根目录中有一堆残骸.这是丑陋和混乱.我从subversion转向git的全部原因是git看起来像一个更清洁,分散的解决方案.此外,我有一些非技术人员将在桌面的根目录中运行,他们会因为这个问题而感到困惑.git的美丽(我认为)所有内容都隐藏在.git文件夹中.编辑:显然我对这一点还不够清楚.想象一下,我有一个带有以下子文件夹的"Documents"文件夹:mydata1和mydata2.这不是一个人为的例子,这正是我试图解决的问题.mydata1应该只包含"test.img"和该文件,但现在它包含:
分支配置描述HEAD挂钩信息对象引用
我希望能够只是cd到mydata1并开始编辑文件,但我必须尝试通过分支机构cd,或者甚至只是为了完成工作.并且为"文档"中的每个子文件夹提供这种目录结构是不可行的.拜托,请不要告诉我这样做.请回答这个问题.谢谢.
这两点是我在这里发布这个问题的全部原因.如果您对此问题有答案,请回复.:) 谢谢!!
cjc*_*343 11
这样做的一种方法是拉,而不是推.在第一台机器上安装两台机器后:
git remote add origin [USER]@laptop:/home/[USER]/git_test
git pull # Complains about untracked branch while adding the branch you want to track
git branch --set-upstream master origin/master
git pull
Run Code Online (Sandbox Code Playgroud)
现在你可以从任何一台机器上提取.如果你想推动,我不知道如何通过分散设置来解决这个问题.