mkdir /git
cd /git
mkdir repository/app.git -p
cd repository/app.git
git init --bare
cd hooks
nano post-receive
#!/bin/bash
TARGET="/usr/share/nginx/repository/app"
GIT_DIR="/git/repository/app.git"
BRANCH="master"
while read oldrev newrev ref
do
if [[ $ref = refs/heads/$BRANCH ]];
then
echo "Ref $ref received. Deploying ${BRANCH} branch to server..."
git --work-tree=$TARGET --git-dir=$GIT_DIR checkout -f
else
echo "Ref $ref received. Doing nothing: only the ${BRANCH} branch may be deployed on this server."
fi
done
# other code bash
chmod +x post-receive
cd /usr/share/nginx/repository
mkdir app
cd /workspace
mkdir app
cd app
git init
git remote add [REMOTE NAME] ssh://user@host.com/git/repository/app.git
git add .
git commit -m "Deploy!"
git push [REMOTE NAME] [BRANCH NAME]
Update file HEAD on git hook if use custom branch
to: