As you requested
I do not recommend you to use the same repo to store your compiled code. Because it can be obtained from any state of source code and it will be unnesessary dublication of information.
So, in this case you want to use git as CI tool. You should create another repo for compiled site and make there commits each time you need it.
I suggest you to choose branch for "production" state of code. And when you commiting in that branch - code should be rebuilded. Lets name it "production".
- Make separate git repo for builded code.
- Put this code to post-commit hook in your src repo. It will handle all commits in the production branch, checkout the code to temporary directory, make build and commit the changes.
srcDir='../srcWorkTree' buildedRepo='../buildedRepo' if [ `git rev-parse --abbrev-ref HEAD` == "production" ]; then echo "making builded code commit..." mkdir -p $srcDir # http://stackoverflow.com/questions/4479960/git-checkout-to-a-specific-folder git checkout-index -a -f --prefix=$srcDir/ bundle exec jekyll build --source $srcDir --destination $buildedRepo cd $buildedRepo git add -A commitInfo=$( git log -1 --pretty="%h %B" ) git commit -m "autobuild for $commitInfo" # git push fi
Another variant
As i can suppose, you have access to your production server. At least you mention that you have git repo there. So it will be reasonable to make there post-receive hook to build your code into target directory. It will be more clear and simple instead of doing it on the local machine as i described.
I suppose that this repo is "bare" because you shouldn't have possibility to make changes on the server.
post-receive hook:
#!/bin/sh siteDir='/var/www/site' tmpSrcDir='/var/www/site' echo "**** [builder's post-receive hook]" while read oldrev newrev refname do if [ $refname = refs/heads/production ] then GIT_WORK_TREE=$tmpSrcDir git checkout --detach $newrev bundle exec jekyll build --source $tmpSrcDir --destination $siteDir fi done exit 0
And few comments
I see, you tryed to use submodule to store your builded site. I don't recommend that. There is no sense because your source code not depends on builded code.