我在这个问题上阅读了几篇SO帖子,但我无法弄清楚我做错了什么。我尝试将我的提交推送到远程分支,但我得到error: failed to push some refs to 'k:/home/projects/tmp/rest-backend'
工作目录
我有一个称为rest-backend
的WD和一个名为rest-backend-branch
的WD。第二个是使用git clone rest-backend rest-backend-branch
创建的。
k:\home\projects\tmp\rest-backend-branch>git remote -v
origin k:/home/projects/tmp/rest-backend (fetch)
origin k:/home/projects/tmp/rest-backend (push)
存储库日志
k:\home\projects\tmp\rest-backend>git log --pretty=oneline --abbrev-commit -4
8526101 Fix sort order
57bbc5b Add favicon
f7a2a24 New client
4f01419 Handle deep link
k:\home\projects\tmp\rest-backend-branch>git log --pretty=oneline --abbrev-commit -4
5294da8 New client
8526101 Fix sort order
57bbc5b Add favicon
f7a2a24 New client
rest-backend-branch
在origin/master
之前提交1次,由git status
显示。
k:\home\projects\tmp\rest-backend-branch>git status
On branch master
Your branch is ahead of 'origin/master' by 1 commit.
(use "git push" to publish your local commits)
nothing to commit, working directory clean
将我的提交推送到远程
如果我尝试将提交推送到origin/master
,我就会收到错误。
k:\home\projects\tmp\rest-backend-branch>git push origin master
Counting objects: 29, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (11/11), done.
Writing objects: 100% (11/11), 101.71 KiB | 0 bytes/s, done.
Total 11 (delta 3), 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'.
To k:/home/projects/tmp/rest-backend
! [remote rejected] master -> master (branch is currently checked out)
error: failed to push some refs to 'k:/home/projects/tmp/rest-backend'
我该如何解决这个问题?
答案 0 :(得分:1)
要解决此问题,您只需按照错误消息中的说明操作即可。将receive.denyCurrentBranch
设置为适合您的任何值 - ignore
或warn
但我们知道结果。
你在这里做的是你克隆了非裸存储库,即这个存储库有一个工作目录。
如果此工作目录现在设置为master
分支,并且您将更改推送到此分支 - 您的工作目录将与分支分离,您必须在那里运行git reset --hard
其他一些解决方案是: