推送到git存储库不起作用

时间:2010-07-07 01:54:03

标签: git version-control versioning

我刚刚开始使用GIT(我来自cvs)并希望使用Git设置类似于cvs / svn的东西。我执行了以下步骤:

cd o:/repository
git init

cd <working directory>
git clone o:/repository

我现在创建了一个名为file.txt的文件,其中包含一些内容 执行“git status”列出了适当的更改。

然后我做

git add file.txt
git commit file.txt

两者似乎都很好。

当我这样做的时候 git push,我收到以下错误:

No refs in common and none specified; doing nothing.
Perhaps you should specify a branch such as 'master'.
fatal: The remote end hung up unexpectedly
error: failed to push some refs to 'o:/repository'

我尝试先进行拉取,并为push命令指定原点和主变量但不起作用。

有人可以告诉我我错过了什么。我正在运行Windows 7 64位。

聚苯乙烯。我也试过

git push origin master

我得到以下内容:

Counting objects: 3, done.
Writing objects: 100% (3/3), 251 bytes, done.
Total 3 (delta 0), reused 0 (delta 0)
Unpacking objects: 100% (3/3), done.
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'.
To O:/repository
 ! [remote rejected] master -> master (branch is currently checked out)
error: failed to push some refs to 'O:/repository'

4 个答案:

答案 0 :(得分:14)

几周前发生在我们身上。这意味着您在原始存储库中检出了工作目录,并且无法进行覆盖。

在您需要裸露存储库的原点。我不知道用一个命令做到这一点的方法。我做了什么(在原始存储库)

> mv repository repository.old
> git clone --bare repository.old repository

我看到你的案例中的起源是o:/ repository。原点不应该是签出的工作副本,因此您可以按照上面的方式初始化裸存储库或副本。要使您描述的方案通过:

cd o:/repository
git init  --bare

cd <working directory>
git clone o:/repository

git push origin master

这应该对你有用:

好读:http://www.gitready.com/advanced/2009/02/01/push-to-only-bare-repositories.html

答案 1 :(得分:5)

对于第一次推送,你需要像

这样的东西
git push origin master

另请参阅push.default option选项。

在任何情况下,如果您以后遇到推送到非裸存储库的问题,那么您也需要阅读相关内容。

答案 2 :(得分:2)

如果您仍希望推送到远程非裸仓库的已检出分支,则现在可以(Git 2。3。0,2015年2月),前提是目标工作树中没有修改过的文件。

在那个远程仓库中,执行:

git config receive.denyCurrentBranch=updateInstead

它比config receive.denyCurrentBranch=ignore更安全:只有在你没有覆盖正在进行的修改时才会允许推送。

commit 1404bcbJohannes Schindelin (dscho)

  

receive-pack:为receive.denyCurrentBranch

添加其他选项      

在工作目录之间进行同步时,通过“push”而非“pull”更新当前分支非常方便,例如:从VM内部推送修复程序时,或推送用户计算机上的修复程序时(开发人员无权安装ssh守护程序,更不用说知道用户的密码)。

     

此修补程序不再需要常见的解决方法 - 推入临时分支然后在另一台计算机上合并。

     

新选项是:

updateInstead
  

相应地更新工作树,但如果有任何未提交的更改,则拒绝这样做。

答案 3 :(得分:0)

如错误消息所述,您尝试推送到的分支(master)将在origin存储库中签出。您可以通过转到o:/repository并查看其他分支来解决此问题。