我有一个 Git 存储库。我已经克隆了存储库并且可以提交我的本地更改。当我将更改推送到服务器时,它可以工作。
一旦我创建了一个分支,我就签出该分支,提交我的工作,然后签出 master 分支。然后我将本地更改合并到主分支中。当我尝试推送到服务器时,出现以下异常:
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
在此之后它可以工作,但我想知道为什么我需要使用这个选项。这是唯一的选择吗?这样做的后果是什么?
我真正想做的是创建分支,将它们合并到主分支中,然后将我的更改推送到服务器。