Step 1: Setup a git repo
Once you have installed your lincensed copy of ExpressionEngine in your local machine, add a directory named DBSchema to the root of the site. Jump in the terminal and initialize a git repository in it:
Step 2: Create and enable hook
After initializing your repo, go to the hidden
.git directory, where you are going to find a
hooks directory. In there create a new file named
pre-commit , and make it executable:
chmod +x pre-commit
Step 3: Add bash script to hook file
Then edit the newly created
pre-commit file and add the following code:
/Applications/MAMP/Library/bin/mysqldump -u $DBUSER -p$DBPASS $DB > $SCHEMAPATH/$DB.sql
git add $SCHEMAPATH/$DB.sql
That's it! What its happening is that we told git that before every commit, run a mysqldump of the database and add it to the stage to be committed.
Note: I would recommend using this only in development, when working in teams before turning over for content or to the client.