Skip to content

Instantly share code, notes, and snippets.

@ozgrozer
Last active April 8, 2018 17:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ozgrozer/6ef144aa7d8a7b8c4afd1739e5539416 to your computer and use it in GitHub Desktop.
Save ozgrozer/6ef144aa7d8a7b8c4afd1739e5539416 to your computer and use it in GitHub Desktop.
Git for deployment

Server

Initialize a bare repository outside of the live server (hub repo).

mkdir -p /var/git/myProject.git
cd /var/git/myProject.git
git init --bare

Initialize a repository inside of the live server (prime repo). And add hub as a remote.

cd /var/www/html/myProject
git init
git remote add hub /var/git/myProject.git
git add .
git commit -m "Initial import of pre-existing web files."
git push hub master

Open vim /var/git/myProject.git/hooks/post-update and paste this.

#!/bin/sh

echo
echo "*** Pulling changes into Live [Hub's post-update hook]"
echo

cd /var/www/html/myProject || exit
unset GIT_DIR
git pull hub master

branch=$(git rev-parse --symbolic --abbrev-ref $1)
if [ "$branch" = "master" ]
then
  # run other commands here like `yarn build`
fi

exec git-update-server-info

Open vim /var/www/html/myProject/.git/hooks/post-commit and paste this.

#!/bin/sh

echo
echo "*** Pushing changes to Hub [Live's post-commit hook]"
echo

git push hub

Make hooks executable.

chmod +x /var/git/myProject.git/hooks/post-update
chmod +x /var/www/html/myProject/.git/hooks/post-commit

Local

Clone repo to the local computer.

cd ~/Desktop
git clone username@ipAddress:/var/git/myProject.git
cd myProject

Ready to development.

echo "test" >> index.html
git add .
git commit -m "First local change."
git push origin master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment