Using git to update my hostgator website
Sometimes updating a static site takes a little used to. You connect to the website through sftp and slowly update every single file. So I was thinking if I could update it in other ways, and there it was - git! And git is installed by hostgator. Hurray!! So here’s how to set git up and automatically update.
So let’s assume you’ve got ssh in your remote website. Login to your website:
ssh [email protected] -p 2222 ... Enter your password: *****
After you’ve logged in, you want to add your public key so you wouldn’t have to key in again.
And add your public key and save. It should be located at ~/.ssh/id_rsa.pub where you copy the key to the authorized_key file. The authorized_key file should look something like this:
<ssh-rsa or ssh-dss> <really long string of nonsense> <username>@<host>
Now change directory to where you’re hosting your website and initialize the git repo.
cd ~/public_html/justinlee git init
In this case, I am using justinlee as the directory of my domain name. Now that you’ve initialized git to run the directory, you’ll have to configure the repo to accept pushes into this working directory.
git config --add receive.denyCurrentBranch ignore
Of course, once commits are pushed, they must be checked out. So add the checked out code here:
GIT_WORK_TREE=../ git checkout -f
And save the following in a file at:
PATH_TO_REPO/.git/hooks/post-receive. In this case:
~/public_html/justinlee/.git/hooks/post-receive and make it executable:
chmod +x PATH_TO_REPO/.git/hooks/post-receive
In this case:
chmod +x ~/public_html/justinlee/.git/hooks/post-receive.
Now, you need to add a remote git in your local computer.
[BACK ON MY COMPUTER] cd ~/justinlee/public/ git remote add name-of-remote ssh://[email protected]:2222/full/path/public_html/your-domain.com
Which in this case:
git remote add hostgator ssh://[email protected]:2222/home1/user-name/public_html/justinlee where user-name and your-domain.com is self-explanatory. You can find the full path in your control panel.
It’s DONE. Finally, I made changes to my content in the markdown and do a hugo and push the changes to git.
cd ~/justinlee hugo cd public git add -A git commit -m "Update site" git push hostgator
Wait a little while, and your website is updated! HUGO FOR THE WIN.