我有一个Git代码库。我已经克隆了这个代码库并可以提交本地更改。当我将更改推送到服务器时,它可以正常工作。
一旦我创建了一个分支,我就会切换到该分支,提交我的工作,然后切换回主分支。然后,我将我的本地更改合并到主分支中。当我尝试将更改推送到服务器时,我会收到以下异常:
Welcome to Git (version 1.7.11-preview20120620)
Run 'git help git' to display the help index.
Run 'git help <command>' to display help for specific commands.
$ git push origin master:master
Counting objects: 9, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (7/7), done.
Writing objects: 100% (8/8), 13.68 KiB, done.
Total 8 (delta 2), reused 1 (delta 0)
Unpacking objects: 100% (8/8), 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 c:/jGit
! [remote rejected] master -> master (branch is currently checked out)
error: failed to push some refs to 'c:/gitRepository'
一个解决方案是运行以下命令:
git config receive.denyCurrentBranch ignore
在使用这个选项后,程序可以正常运行,但我想知道为什么需要使用这个选项。这是唯一的选项吗?这样做会有什么后果?
我真正想做的是创建分支,将它们合并到主分支中,然后将更改推送到服务器。
receive.denyCurrentBranch
的默认值是什么? - lindhegit config receive.denyCurrentBranch updateInstead
。 - Fanky