同じ問題に苦しんでいる間、私は2日前にこのスレッドに出くわしました。ようやくきちんとした解決策にたどり着いた後、私はそれについての記事をここに書きました:
サブモジュールを使用したGitプッシュ:ハウツーガイド
push
ベアリポジトリにアクセスする場合は、非ベアリポジトリに使用するpost-receive
ためpull
だけに、シンプルにpush
直接非ベアリポジトリに保存する方がよいことに気付きました。これは、ベアリポジトリにプッシュするだけの「ベストプラクティス」が複雑さを増すだけであるという明確なケースです。
リンク切れの場合は、ここに解決策を貼り付けます。あなたが行ったと確信しているのと同じ問題がすべて発生する部分をスキップします。
まず、リポジトリごとに変更する必要のないユニバーサル フックを作成しましょう。post-receive
[aaron@aaronadams]$ cat > /usr/local/share/git-core/templates/hooks/post-receive.sample
#!/bin/sh
#
# An example hook script to update the working tree, including its
# submodules, after receiving a push.
#
# This hook requires core.worktree to be explicitly set, and
# receive.denyCurrentBranch to be set to false.
#
# To enable this hook, rename this file to "post-receive".
# Read standard input or hook will fail
while read oldrev newrev refname
do
:
done
# Unset GIT_DIR or the universe will implode
unset GIT_DIR
# Change directory to the working tree; exit on failure
cd `git config --get core.worktree` || exit
# Force checkout
git checkout --force
# Force update submodules
git submodule update --init --recursive --force
[aaron@aaronadams]$ chmod +x /usr/local/share/git-core/templates/hooks/post-receive.sample
それでは、先に進んですべてのルールを破りましょう。
Webサイトディレクトリにある非ベアGitリポジトリを初期化します。から受信できることを確認してくださいgit push
; 作業ツリーをその親ディレクトリに明示的に設定します。作成したフックを有効にします。
[aaron@aaronadams]$ cd /var/www/vhosts/aaronadams.ca/sites/staging.aaronadams.ca
[aaron@aaronadams]$ git init && git config --bool receive.denyCurrentBranch false && git config --path core.worktree ../ && mv .git/hooks/post-receive.sample .git/hooks/post-receive
Initialized empty Git repository in /var/www/vhosts/aaronadams.ca/sites/staging.aaronadams.ca/.git/
最後に、ローカルマシンで、新しいリポジトリの場所を反映するようにリモートを変更し、プッシュします。
[aaron@aaronadams]$ git remote set-url staging aaron@aaronadams.ca:sites/staging.aaronadams.ca
[aaron@aaronadams]$ git push staging master
remote: Submodule 'codeigniter' (git://github.com/EllisLab/CodeIgniter.git) registered for path 'codeigniter'
remote: Cloning into 'codeigniter'...
remote: Submodule path 'codeigniter': checked out 'fd24adf31255822d6aa9a5d2dce9010ad2ee4cf0'
To aaron@aaronadams.ca:sites/staging.aaronadams.ca
* [new branch] master -> master
神聖ながらくた、それはうまくいきました!
このメソッドはサブモジュールと互換性があるだけでなく、新しいリモートリポジトリをセットアップするために必要なコマンドは1つだけです(これは4つのコマンドで構成されています)。また、リポジトリと作業ツリーを同じ場所に保持します。また、構成ファイルやフックファイルに絶対パスが必要ないため、完全に移植可能になりました。
この回答が、過去2日間に他の人のStack Exchangeの投稿が私を助けてくれたのと同じくらい、誰かに役立つことを願っています!