Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/git/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
git推送到远程主分支_Git - Fatal编程技术网

git推送到远程主分支

git推送到远程主分支,git,Git,我有一个远程和一个本地git存储库。 本地存储库是从远程克隆的。 当我修改本地存储库并提交到主分支时。 然后我运行“git push”到远程存储库。 但它失败并输出以下消息 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: err

我有一个远程和一个本地git存储库。
本地存储库是从远程克隆的。
当我修改本地存储库并提交到主分支时。
然后我运行“git push”到远程存储库。
但它失败并输出以下消息

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 t
remote: error: 'ignore' or 'warn' in the remote repository to allow pushing int
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 som
remote: error: other way.
remote: error: 
remote: error: To squelch this message and still keep the default behaviour, se
remote: error: 'receive.denyCurrentBranch' configuration variable to 'refuse'.
I“git checkout-b current”远程存储库中的另一个分支。
在本地存储库中,我运行“git push”,然后it成功。
但是本地修改只推送到远程主分支。
然后,我应该在远程存储库中运行“git merge master”来接受更改

我是git的新手。

我做错了吗?

远程存储库不是裸存储库,已签出master。而且,默认情况下,git不允许您推送到非裸回购的签出分支


理想情况下,您推送到的远程回购应该设置为裸回购(
git init--bare
)。

当我刚加入github时,我的导师给了我以下经验法则:

在本地修改代码。提交时,请执行以下操作:

  • do
    git pull
    (将远程回购的内部引用头同步到本地存储库非常重要)
  • 如果不同文件中存在任何冲突,请通过选择您的副本或远程副本,或通过在Kdiff中打开这两个文件来仔细合并它们。一旦解决了所有冲突,就推动合并
  • 在第2步之后,执行
    git push
    ,保存您对首先要提交的代码所做的本地更改
  • Subversion可能是一种痛苦,但保持同步非常重要。 这些规则对我使用github维护子版本有很大帮助。
    希望这有帮助

    manojlds的回答是正确的,但是了解远程回购的目的可能会有所帮助

    • 如果远程回购只是出于备份/协作目的->您的想法是正确的,只需将远程回购替换为“裸”回购即可
    • 如果远程repo是生产服务器,那么您做错了->您应该有不同的配置
    一个很好的确认,以便您能够“推动生产”,就是让您的“裸”repo用于备份/协作目的,然后在部署服务器上设置一个单独的repo,并从裸repo克隆。然后在裸repo上,您可以放置一个“post-receive-hook”,使部署repo执行拉操作


    我相信有关于如何做到这一点的指南。。。我自己也有过这样一次:)

    可能与相同的重复,我认为这对OP没有帮助,因为你说的是slipslop将军,而不是他的问题。关于你的经验法则:我认为这是错误的。到了该提交的时候,提交。时期没有别的了。当是时候将事情放回到另一次回购中时,您必须执行类似于
    提取
    重设基础
    拉取
    或类似操作。然后解决冲突。然后按
    按钮
    。在步骤3中,您的本地提交被发送到远程repo。SVN不是一件痛苦的事,它是一件痛苦的事。我现有的回购协议可以被设置为裸机回购(git-init--bare)吗?我不这么认为,但是如果它是一个基于linux的主机,并且你的回购协议名为“foo”,那么它就简单得像这样:
    mv-foo-foo-2
    mkdir-foo
    cd-foo
    git-init---bare
    git-remote-add-origin./../foo2
    git-pull