How I setup git for my WordPress installation in BlueHost

Im not sure if this is the “proper” way to do it. Well, it sort of works for me at the moment so I thought I’ll share it here. I did use FTP at first (using FileZilla) but I didnt really like the workflow.

Prerequisites

Server/Host side

cp -rv ~/public_html/ ~/www-checkout/
mv ~/public_html ~/public_html_original
ln -s ~/www-checkout ~/public_html
mkdir www.git
cd www.git
git --bare init
cd hooks
touch post-receive
chmod 755 post-receive

Contents of post-receive (edited using vim)

#!/bin/sh
GIT_WORK_TREE=~/www-checkout git checkout -f
cd && mkdir www-work
cd www-work
git clone ~/www.git
git add --all
git commit -a -m "Initial commit."
git push -u origin master

Thats it. Now to the client side.

Client side

git clone <username>@<domain>:~/www.git

I now have a working source copy in my Windows client machine!

Disadvantages?

One thing I can think of is that every edit goes directly to live folder. So I dont have a sort of “staging” server for me to test before putting changes to live. Both a blessing and a curse, I think. But then again, this is just a simple blog, using a free theme, so I dont think I will be doing any massive changes to the source code anyway.

---
If you have any questions or feedback, please reach out @flowerinthenyt.

Creative Commons License
This work is licensed under a Creative Commons Attribution 4.0 International License.