Git pull 和 push 不起作用
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13746606/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Git pull and push don't work
提问by Jānis Gitendorfs
I cloned an empty repository from a personal git server. After initial push (push -u origin master
) I got some error but I pushed inside.
我从个人 git 服务器克隆了一个空存储库。初始推 ( push -u origin master
) 后,我遇到了一些错误,但我推了进去。
Trying to use git push
displays the following:
尝试使用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 'link-top-repository'
没有共同的参考文献,也没有指定;什么也不做。也许您应该指定一个分支,例如“master”。致命:远程端意外挂断错误:无法将某些引用推送到“链接顶部存储库”
Then I tried git push origin 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'.
Problem starts when using git pull
:
使用时出现问题git pull
:
Your configuration specifies to merge with the ref 'master' from the remote, but no such ref was fetched.
您的配置指定与来自远程的 ref 'master' 合并,但未获取此类 ref。
I tried to check .git/config but it seems correct.
我试图检查 .git/config 但它似乎是正确的。
[core]
repositoryformatversion = 0
filemode = true
bare = false
logallrefupdates = true
ignorecase = true
[remote "origin"]
fetch = +refs/heads/*:refs/remotes/origin/*
url = [email protected]:/repository/regulator
[branch "master"]
remote = origin
merge = refs/heads/master
[branc "master"]
remote = origin
Any suggestions?
有什么建议?
回答by Riza
assuming that you have write access to your personal git server, what you are doing is pushing changes to a non-bare repository, and to a branch that are currently checked out as working directory.
假设你对你的个人 git 服务器有写访问权限,你正在做的是将更改推送到非裸存储库,以及当前作为工作目录签出的分支。
The current common good practices is always push to a bare repository. To create it, you could do something like this:
当前常见的良好做法始终是推送到裸存储库。要创建它,您可以执行以下操作:
git init --bare SomeRepo.git
if you insist on pushing to a non-bare repository, which is not recommended, make sure that the branch that you are going to push to is not the current checked out branch or the current working directory. just open a command line tools, such as terminal in Linux or git bash in windows, move to your repository directory (the one that has a folder .git in it), execute this command:
如果您坚持推送到非裸存储库(不推荐),请确保您要推送到的分支不是当前签出的分支或当前工作目录。只需打开命令行工具,例如 Linux 中的终端或 Windows 中的 git bash,移动到您的存储库目录(其中包含 .git 文件夹的目录),执行以下命令:
git branch -v
it will show all the available branches of that repository, and the branch that currently checked out is marked with '*', for example:
它将显示该存储库的所有可用分支,当前检出的分支标有“*”,例如:
* master b0bb0b1 some commit message
development babbab2 some other commit message
experimental bebbeb3 some commit message in experiment
the example above shows that master is the currently checked out branch, thus you couldn't push to it. But you could push to other branches, such as development or experimental. If you must push to master, you could do it by changing the current directory to other branches, using this command:
上面的例子显示 master 是当前检出的分支,因此你不能推送到它。但是您可以推送到其他分支,例如开发或实验。如果必须推送到 master,可以使用以下命令将当前目录更改为其他分支:
git checkout the_branch_name
after this, the currently checked out is the branch that specified in above command, pushing to master is now possible.
在此之后,当前检出的是上面命令中指定的分支,现在可以推送到 master。
回答by Rawkode
Remove this from the end of your file.
从文件末尾删除它。
[branc "master"]
remote = origin
Also - your central Git repository where your developers push
to, should be a bare repository. Your error logs show that yours isn't.
此外 - 您的开发人员所在的中央 Git 存储库push
应该是一个裸存储库。您的错误日志显示您的不是。
回答by Sander
I had a similar problem and found the answer in the Unix stack-exchange: https://unix.stackexchange.com/a/166713
我有一个类似的问题,并在 Unix 堆栈交换中找到了答案:https: //unix.stackexchange.com/a/166713
In my case, my local branch and remote branch had different capitalization.
To resolve this I deleted my local branch
$ git branch -d branch-name
, then checked out the remote branch again using$ git fetch
and$ git checkout Branch-name
.
就我而言,我的本地分支和远程分支的大小写不同。
为了解决这个问题,我删除了我的本地分支
$ git branch -d branch-name
,然后再次使用$ git fetch
and签出远程分支$ git checkout Branch-name
。
So deleting the local branch and checking out the remote branch again fixed it.
所以删除本地分支并再次检查远程分支修复它。