In order to update my website remotely with git, I have created a bare git repo at the root of my shared hosting account together with the following post-receive hook:
#!/bin/sh
export GIT_WORK_TREE=/public_html
git checkout -f
This initially worked as intended: when pushing my changes to the remote repo, the post-receive hook fired and files were checked out to the /public_html folder.
However, I am now getting a "fatal: This operation must be run in a work tree" error on checkout. I have no clue why this error is appearing now, since I haven't made any change to my setup.
I am stuck. To me this should just work (and it actually did), unless I have completely misunderstood how git works. I have been looking for questions similar to mine but haven't found anything useful so far.
I would be grateful for any idea where I should look.
Hooks run in the .git dir.
I have used cd .. before git checkout in the hook as a simple workaround.
If the .git repo is fully disjoint from the checkout location, you could also conceivably
cd /path/to/checkout
GIT_DIR=/path/to/repo/.git git checkout -f
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With