Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/git/22.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/66.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_Github_Version Control - Fatal编程技术网

Git 既然本地存储库和远程存储库都在本地计算机上,为什么我不能将它们从本地存储库推送到远程存储库?

Git 既然本地存储库和远程存储库都在本地计算机上,为什么我不能将它们从本地存储库推送到远程存储库?,git,github,version-control,Git,Github,Version Control,我正在学习如何在Mac OS Sierra上使用git,我在本地机器上创建了一个远程复制库和一个本地存储库 我git init远程repo和git克隆它到我的本地repo。当我更改本地回购协议时,我遵循以下程序: git diff git status git add -A git commit -m "" git pull origin master 然后我git推原始主机,得到了这个错误消息 Counting objects: 3, done. Delta compression us

我正在学习如何在Mac OS Sierra上使用git,我在本地机器上创建了一个远程复制库和一个本地存储库

git init
远程repo和
git克隆
它到我的本地repo。当我更改本地回购协议时,我遵循以下程序:

git diff
git status 
git add -A 
git commit -m ""
git pull origin master
然后我
git推原始主机
,得到了这个错误消息

Counting objects: 3, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (3/3), done.
Writing objects: 100% (3/3), 340 bytes | 0 bytes/s, done.
Total 3 (delta 0), reused 0 (delta 0)
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'.
To /Users/iivri.andre/local-repo/../git
 ! [remote rejected] master -> master (branch is currently checked out)
error: failed to push some refs to '/Users/iivri.andre/local-repo/../git'

我怎样才能纠正这个问题

您必须像这样创建远程git

git init --bare 
你可以看到

我怎样才能纠正这个问题

有两种选择。首先是将您正在推送的回购协议放在一个空存储库中。这是将远程克隆作为裸克隆的首选方式

通常,您会从一个裸repo开始,
gitinit--bare
,然后从中克隆。但既然你有一个现有的回购协议,最简单的方法就是对它进行简单的复制

git clone --bare path/to/that/repo
现在,通过克隆新的裸机克隆,或者使用git remote set url origin path/to/the/bare/clone
将其作为远程推送对象


另一种选择是按照说明进行操作,并告诉Git无论如何都让您推

cd the/remote/repo
git config receive.denyCurrentBranch ignore

这是个坏主意。推送将更新存储库,但不会更新签出的文件(即工作目录)。如果有人正在使用该存储库,它将变得非常混乱。如果您的目的是通过推送更新该回购协议的签出,那么这是行不通的。

您的远程存储库
origin
不是裸存储库,这意味着它包含您的代码的签出版本。具体地说,错误消息告诉您,签出的
原点
上的分支与您尝试推送到的分支相同

当你推的时候,会发生很多事情,特别是:

  • 提交被添加到历史记录中
  • 分支指针被移动
第二点是错误消息的具体内容。拥有该回购协议的人(在本例中是您,但这不是一项要求)已经签出了分支机构
主库当时定义的存储库的特定状态。如果你推到他们的回购,他们的
指针将移动以包括你的新提交。如果git允许您的推送按原样进行,那么您将更改其他人的工作副本上的文件,这些文件可能是他们立即知道的,也可能不是他们立即知道的

要将您的承诺从一个非裸回购协议转移到另一个非裸回购协议,您有许多可用选项:

  • 您可以将远程从第一个repo添加到第二个repo,并获取新的提交
    • git远程添加功能
    • git获取功能
    • git merge-feature/master
      (我个人喜欢使用--ff-only标志)
  • 您可以重命名非原始回购的
    master
    分支,并推送该分支
    • git分支-m主功能\u主功能
    • git推送原点功能\u master
    • cd
    • git合并功能\u master
      (同样,我在这里只使用--ff)
  • 您可以对源存储库上的
    分支执行相同的重命名。我不建议这样做,因为现在您必须确保
    源代码/重命名的\u主代码
    上没有需要重新设置基础或合并到新
    主代码