Skip to content

Instantly share code, notes, and snippets.

@lslucas
Last active October 18, 2019 08:51
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save lslucas/5860542 to your computer and use it in GitHub Desktop.
Save lslucas/5860542 to your computer and use it in GitHub Desktop.
Git Deploy Management
First, make sure you already have git installed on local and remote server.
On remote server
----------------
$ cd ~/ #if you are not here yet
$ mkdir website.git && cd website.git
$ git init --bare
Initialized empty Git repository in /home/ubuntu/website.git/
$ vi hooks/post-receive # paste the post-receive file here
$ chmod +x hooks/post-receive
Make sure you already created the folder with right permissions where your website will go, in this case our website is going on /var/www/site
On workstation
--------------
Now on your computer, go to your project folder then add our recently created remote server:
$ git remote add deploy ssh://user@ip/home/user/website.git
$ #on first push:
$ git push deploy +master:refs/heads/master
Now you are ready to go, everytime to deploy the files just use:
$ git push deploy
Common errors
-------------
On push deploy, if you get something like this: fatal: 'user@ip/home/ubuntu/website.git' does not appear to be a git repository. Make sure you add ssh:// on remote address, like this ssh://user@ip/home/ubuntu/website.git
#!/bin/bash
while read oldrev newrev ref
do
branch=`echo $ref | cut -d/ -f3`
if [ "master" == "$branch" ]; then
git --work-tree=/var/www/site/ checkout -f $branch
echo 'Changes pushed live.'
fi
done
#!/bin/bash
while read oldrev newrev ref
do
branch=`echo $ref | cut -d/ -f3`
if [ "master" == "$branch" ]; then
git --work-tree=/var/www/site/ checkout -f $branch
echo 'Changes pushed live.'
fi
if [ "labs" == "$branch" ]; then
git --work-tree=/var/www/site-labs/ checkout -f $branch
echo 'Changes pushed to labs'
fi
if [ "dev" == "$branch" ]; then
git --work-tree=/var/www/site-dev/ checkout -f $branch
echo 'Changes pushed to dev'
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment