Git拉和推不起作用

时间:2012-12-06 15:12:44

标签: git

我从个人git服务器克隆了一个空存储库。在初始推送(push -u origin master)之后,我遇到了一些错误,但我推进了内部。

尝试使用git push会显示以下内容:

  

没有共同的参考,没有指定;什么也不做。也许你   应该指定一个分支,例如'master'。致命的:远程端挂了   意外错误:无法推送一些参考   “链路顶库”

然后我尝试了git push origin master

Counting objects: 3, done.
Writing objects: 100% (3/3), 218 bytes, 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 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 pull时会出现问题:

  

您的配置指定与来自的“ref”master合并   远程,但没有提到这样的参考。

我试过检查.git / config但似乎是正确的。

[core]
        repositoryformatversion = 0
        filemode = true
        bare = false
        logallrefupdates = true
        ignorecase = true
[remote "origin"]
        fetch = +refs/heads/*:refs/remotes/origin/*
        url = junior@54blue.com:/repository/regulator
[branch "master"]
        remote = origin
        merge = refs/heads/master
[branc "master"]
        remote = origin

有什么建议吗?

3 个答案:

答案 0 :(得分:5)

假设您具有对个人git服务器的写入权限,您正在做的是将更改推送到non-bare repository,以及当前检出为工作目录的分支。

目前常见的良好做法总是推向裸存储库。要创建它,您可以执行以下操作:

git init --bare SomeRepo.git

如果您坚持要推送到非裸存储库(不推荐使用),请确保要推送到的分支不是当前签出的分支或当前工作目录。只需打开命令行工具,例如Linux中的终端或Windows中的git bash,移动到您的存储库目录(其中包含文件夹.git的目录),执行以下命令:

git branch -v

它将显示该存储库的所有可用分支,并且当前签出的分支标有“*”,例如:

* master        b0bb0b1 some commit message
  development   babbab2 some other commit message
  experimental  bebbeb3 some commit message in experiment

上面的示例显示master是当前签出的分支,因此您无法推送它。但你可以推动其他分支,如开发或实验。如果必须推送到master,可以使用以下命令将当前目录更改为其他分支:

git checkout the_branch_name

此后,当前签出的是上面命令中指定的分支,现在可以推送到master。

答案 1 :(得分:0)

从文件末尾删除它。

[branc "master"]
        remote = origin

此外 - 您的开发人员push所在的中央Git存储库应该是一个裸存储库。您的错误日志显示您的错误日志不是。

答案 2 :(得分:0)

我遇到了类似的问题,并在Unix堆栈交换中找到了答案: https://unix.stackexchange.com/a/166713

  

在我的情况下,我的本地分支和远程分支有所不同   大写。

     

要解决此问题,我删除了我的本地分支$ git branch -d branch-name,   然后使用$ git fetch$ git checkout Branch-name再次检出远程分支。

因此,删除本地分支并再次检出远程分支。

相关问题