git push が失敗します: `チェックアウトされたブランチの更新を拒否します: refs/heads/master` 質問する

git push が失敗します: `チェックアウトされたブランチの更新を拒否します: refs/heads/master` 質問する

JBoss 構成へのローカル変更を Git に保存したいと考えています。そのために、次の構造を設定しました。

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は、"origin" となる Git リポジトリです。アイデアとしては、アップデートが利用可能になったら、JBoss ディストリビューションを簡単にアップデートできるようにしたいということです。配布された JBoss パッケージに対するすべてのローカル変更を Git に保存したいと考えています。

そこで、現在私は次のようにしています:

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

current現在、ディレクトリ内のブランチは~/local常に最新ですが、チェックアウトされていないため、そこにプッシュすることはできません。

ベストアンサー1

プッシュはベア リポジトリを対象としています。ベアでないリポジトリの場合は、プルする必要があります。

とにかくこれを強制したい場合は、エラー メッセージに従って、receive.denyCurrentBranch を無視するように設定します。プッシュ先のリポジトリの場所に SSH で接続し、次を実行します。

git config receive.denyCurrentBranch ignore

おすすめ記事