Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using git to publish to a website

I used this guide to use git to autopublish my changes on my website when I push to my remote origin git repository:

http://www.lwp.ca/james/2010/03/using-git-to-manage-online-website-projects/

Here's my /hooks/post-update file:

cd ../../public_html/dir/wbg
env -i git pull

Here's my directory structure:

/home/git/wbg.git <-- my remote git repository

/home/public_html/dir/wbg <-- my web folder

When I run

git push origin master

The repository updates but my web folder is still empty. Any ideas?

Edit: if any future traffic sees this, my real problem was that BOTH your remote origin AND your destination website directory must be git repositories. You can't just set it up to copy your project to a new folder unless that folder is also a git repo.

like image 955
Citizen Avatar asked Feb 08 '11 20:02

Citizen


People also ask

Can you host your website on Git?

Steps for Hosting a Website on GitHubCreate a GitHub account on github.com. Download either GitHub for Mac or GitHub for Windows, depending on your operating system. Open the app and log in using the account you just created. (On Mac): After you login, click advanced and make sure that your name and email are correct.

Can you publish from GitHub?

You can configure your GitHub Pages site to publish when changes are pushed to a specific branch, or you can write a GitHub Actions workflow to publish your site. People with admin or maintainer permissions for a repository can configure a publishing source for a GitHub Pages site.


2 Answers

You can find a better alternative at http://toroid.org/ams/git-website-howto that only uses one git repository, and allows all metadata and previous history to remain outside of the DocumentRoot.

The guide you used and the one I linked referrer to another article both are based on, but the one I linked seems to be the preferred one to direct new users to in the #git IRC channel.

like image 98
Arrowmaster Avatar answered Sep 18 '22 00:09

Arrowmaster


Not a lot to go off of here, but I can report that I successfully use a similar method to this.

For my purposes, I call my bare server repository the "Hub" and my web-facing repository the "Prime". Make sure that you have properly initialized a git repository in your server htdocs directory (Prime) and have either pushed the changes to the bare repository (Hub) or pulled them in.

This is the post-update hook I use, which is in my Hub repository's hooks directory:

#!/bin/sh

echo
echo "*** Pulling changes into Prime"
echo

cd /path/to/htdocs/ || exit
unset GIT_DIR
git pull hub master

exec git-update-server-info

Make sure this is executable! If in doubt, just edit the post-update.sample file and remove the .sample extension when done. The echoed text gives nice feedback that the copying is actually taking place. If you don't see that text, then it's not pulling the changes. And if you're not going to call your remote repository "hub", replace it with "origin" or whatever you decide to use.

As a precaution so that my Prime and local repositories don't get too out of whack, I have this as my Prime post-commit hook:

#!/bin/sh

echo
echo "*** Pushing changes to Hub"
echo

git push hub

Then I can just pull the changes from Hub into my local repository.

like image 36
mybuddymichael Avatar answered Sep 18 '22 00:09

mybuddymichael