git推送失败:拒绝更新签出分支:refs / heads / master

我想将我的本地修改保存到git中的JBossconfiguration。 为此,我build立了以下结构:

lrwxrwxrwx 1 jboss jboss 19 Jan 24 11:53 current -> jboss-as-7.1.0.CR1b drwxr-xr-x 11 jboss jboss 4096 Jan 24 12:13 jboss-as-7.1.0.CR1b -rw-r--r-- 1 jboss jboss 108211143 Jan 23 16:02 jboss-as-7.1.0.CR1b.tar.gz drwxr-xr-x 6 jboss jboss 4096 Jan 24 11:36 local 

local是git仓库,它应该是“原点”。 这个想法是,我希望能够在更新可用时轻松更新我的JBoss发行版。 我想在git中存储所有本地修改的分布式JBoss包。

所以,目前我这样做:

 jboss@tpl0:~/jboss-as-7.1.0.CR1b$ git init Initialized empty Git repository in /opt/jboss/jboss-as-7.1.0.CR1b/.git/ jboss@tpl0:~/jboss-as-7.1.0.CR1b$ git remote add origin ../local/ jboss@tpl0:~/jboss-as-7.1.0.CR1b$ git pull origin master From ../local * branch master -> FETCH_HEAD 

到目前为止,所有的地方修改都在我想要的地方。

但是,一旦我进行了本地修改,并希望将其重新安装到local存储库,则会出现以下错误:

 jboss@tpl0:~/jboss-as-7.1.0.CR1b$ vim standalone/configuration/standalone.xml jboss@tpl0:~/jboss-as-7.1.0.CR1b$ git commit -a -m "renamed database to project2_core, to distinguish from other projects" [master 3e54f34] renamed database to project2_core, to distinguish from other projects Committer: jboss <jboss@tpl0.(none)> 1 files changed, 1 insertions(+), 1 deletions(-) jboss@tpl0:~/jboss-as-7.1.0.CR1b$ git push origin master Counting objects: 9, done. Compressing objects: 100% (4/4), done. Writing objects: 100% (5/5), 447 bytes, done. Total 5 (delta 3), reused 0 (delta 0) Unpacking objects: 100% (5/5), 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 t remote: error: 'ignore' or 'warn' in the remote repository to allow pushing int 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 som remote: error: other way. remote: error: remote: error: To squelch this message and still keep the default behaviour, se remote: error: 'receive.denyCurrentBranch' configuration variable to 'refuse'. To ../local/ ! [remote rejected] master -> master (branch is currently checked out) error: failed to push some refs to '../local/' 

我能做些什么呢? 任何帮助是极大的赞赏!

编辑

这就是我所做的,解决了这个问题:

 cd ~/current git init vim .gitignore # set up a basic .gitignore file git add .gitignore git commit -a -m "initial commit" cd ~/local git clone ~/current git branch -m master current # rename master branch to 'current' git branch repo git checkout repo 

现在,目录~/local的分支current总是最新的,但是没有被取消,所以我可以推进它。

远程站点的主分支被检出。 如果您有权访问远程存储库,请检出其他分支,然后从存储库中进行推送。

推是为了裸回购。 对于非裸回购,你应该把它们拉进去。

如果您想要强制执行此操作,则可以按照错误消息的说明进行操作,并将receive.denyCurrentBranch设置为忽略。 SSH到您正在推送并运行的回购的位置:

 git config receive.denyCurrentBranch ignore 

创build原始(本地)存储库作为裸存储库(即git init –bare),或签出一个不是主的分支。

要么,

当你初始化你的远程项目时,使用

 git init --bare 

我设法通过从“当地”“当地”拉动而不是从“当地”推动到“当前”。

我知道这是一个相当古老的问题,但如果你使用git init –bare,请注意'GIT_DIR ='。 这将被设置为一个裸露的回购钩,如果使用挂钩来检查回购后推。 在你的钩子程序中使用'export GIT_DIR = .git'来使它识别你正在进入的回购。