i have my local Git repos and a remote repository (hub). I use post-update hook to copy my project (/home/user/projects/website.com) into apache's git repo inside public_html. I have follow this tutorial: using-git-for-deploymen. Bellow is my post-update. I had problems with conflicts with the 2 first ways (i need to resolve conflicts automatically when copy project from remote(hub) into live, simple copy) but the 3rd works fine:
#!/bin/sh
#
# An example hook script to prepare a packed repository for use over
# dumb transports.
#
# To enable this hook, rename this file to "post-update".
echo
echo "**** Pulling changes into Live [Hub's post-update hook]"
echo
cd /home/user/website.com/public_html || exit
unset GIT_DIR
# 1st way: simple point head into hub
#git fetch hub master 2>&1
#git reset --hard FETCH_HEAD 2>&1
#git clean -df 2>&1
# 2nd way: merge (you may have conflicts)
#git fetch hub master 2>&1
#git reset --hard master 2>&1
#git pull --rebase hub master 2>&1
# 3rd way: Combining the above
git fetch hub master 2>&1
git reset --hard FETCH_HEAD 2>&1
git pull --rebase hub master 2>&1
# allow write permission to group
chmod -R g+w public_html/
exec git update-server-info
All good so far, but post-commit inside live repo, described in this tutorial isn't working and i'm losing changes when made from ftp into live site directly. All that i need is every time a pull from a local git repo is made, a hook to go into live repo, pull from remote into live, commit changes that have been made from ftp access into live, push them into remote and then pull the remote into local repo. I have tried post-merge hook inside my project remote repo (hub) to do that, but i have conflicts and is not working as expected. Here is my post-merge:
#!/bin/sh
#
# An example hook script that is called when a git pull is done
# on a local repository.
#
# To enable this hook, rename this file to "post-merge".
echo
echo "**** pushing changes from Live to Hub [Hub's post-merge hook]"
echo
cd /home/user/website.com/public_html || exit
unset GIT_DIR
## fetch hub's data ##
git fetch hub master 2>&1
#git merge master
git reset --hard master 2>&1
git pull --rebase hub master 2>&1
## Push changes ##
git add -A
git commit -m "Changes from Live"
git push hub master 2>&1
## Change group permissions ##
chmod -R g+w public_html/
# exec git update-server-info
# : Nothing
Every time i run post-merge i'm getting this message on push:
! [rejected] master -> master (non-fast-forward)
error: failed to push some refs to '/home/git/Sites/trofodosies24.git'
To prevent you from losing history, non-fast-forward updates were rejected
Merge the remote changes before pushing again. See the 'Note about
fast-forwards' section of 'git push --help' for details.
What am i doing wrong? Please help.