My Git for Web Site How-to

Install Git and setup passwordless ssh access

Refer to Using Git to Manage a Live Web Site.

Prepare repository on webserver (example used on ubuntu 22.04)

Initialize a Git folder

    sudo git init --bare --shared {website_name}.git && cd $_

Generate post receive hook

    sudo nano hooks/post-receive

Contents for post-receive (folder path assumed for nginx default path structure)

    #! /bin/sh
    GIT_WORK_TREE=/var/www/{website_name}/html git checkout -qf --detach main

Make post receive hook executable

    sudo chmod +x hooks/post-receive

Prepare on local machine (example used on os x 12.6)

Execute in the local website root folder

    git init
    git add -A
    git commit -m "Initial Commit"

Point to remote

    git remote add live ssh://{user}@{webserver}/{path_to}/{website_name}.git
    git push live +main:refs/heads/main
    git push --set-upstream live main

Then to push updates after local changes

    git add .
    git commit -a -m "some comment"
    git push live


Creative Commons Attribution-ShareAlike 4.0 International License