I followed the “Doing it the right way section.” with a minor modification that I didn’t set the post-receive hook as the default. That changes the following command:
git init && git config --bool receive.denyCurrentBranch false && git config --path core.worktree ../ && mv .git/hooks/post-receive.sample .git/hooks/post-receive
Instead, I use:
git init && git config --bool receive.denyCurrentBranch false && git config --path core.worktree ../
Once done, I set the post-receive hook to the following script (from the page).
#!/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
Hope that helps. I am using this method for a Kirby site with two remotes. I have a development remote that I push the dev branch to and production remote that I push the master branch to. Works great.