Git pull和push无法使用

3
我从个人的git服务器上克隆了一个空仓库。在初始提交(push -u origin master)之后,我遇到了一些错误,但是我还是将其推送成功了。
尝试使用git push命令会显示以下信息:

没有共同的引用,并且没有指定任何引用; 什么也没做。可能你应该指定一个分支,比如'master'。致命错误:远程服务器意外终止。错误:未能推送到'link-top-repository'

然后我尝试了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时出现问题:

您的配置指定将与远程的'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

有任何建议吗?

可能是重复问题:https://dev59.com/uWgu5IYBdhLWcg3wuJWF - jchapa
3个回答

5
假设您对个人的Git服务器拥有写访问权限,那么您正在做的是将更改推送到当前作为工作目录检出的分支上的非裸库中。
当前通用的最佳实践是始终向裸库推送。要创建它,可以这样做:
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是当前检出的分支,因此您无法将其推送。但是您可以将其推送到其他分支,例如development或experimental。如果必须将其推送到master,则可以通过将当前目录更改为其他分支,并使用此命令来执行:

git checkout the_branch_name

执行上述命令后,当前检出的是指定的分支,现在可以将其推送到主分支。


0

从文件末尾删除此内容。

[branc "master"]
        remote = origin

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

删除了那两行代码,但是没有任何变化。仍然一样。 - Jānis Gitendorfs
看起来是在向非裸库推送。为什么会这样? - Rawkode
我需要创建一个裸仓库吗? - Jānis Gitendorfs
如果那是你的“中央”代码库,那么是的,它应该是裸的。这意味着它不能在本地修改,你的推送也不会引起问题。 - Rawkode

0

我曾经遇到过类似的问题,并在Unix stack-exchange上找到了答案: https://unix.stackexchange.com/a/166713

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

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

因此,删除本地分支并重新检出远程分支解决了这个问题。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接