Are you using git yet? Are you deploying your website via
git push? - You should!
The goal of this post is to give you a short overview of my way to get git automatically deploy a website via
git push on uberspace.de.
I will use metalmatze.de as domain and metalmatze as examples (my site is not hosted on uberspace).
What we want to do
git push uberspace master- This will push new commits to uberspace and deploy your site.
- Check metalmatze.de to see the changes we just pushed.
Connect with ssh to uberspace.
$ ssh firstname.lastname@example.org
Create a new folder in your home directory (you should be there after connecting) called metalmatze.de.git
$ mkdir metalmatze.de.git
Change into this directory with
Next we want to create a bare git repository
$ git init --bare Initialized empty Git repository in /home/metalmatze/metalmatze.de.git/
The following steps will take place in your local repository!
Now we want to add uberspace as a remote repository to our local repository
$ git remote add uberspace ssh://email@example.com/home/metalmatze/metalmatze.de.git
The following steps will take place on uberspace in the bare git repository!
To get git to deploy our website into a specified folder we'll use a post-receive hook.
hooks/post-receive with an editor like vim or nano.
$ vim hooks/post-receive
Into this file we'll paste a simple bash script that will deploy the master branch into
#!/bin/bash path="/home/metalmatze/html/metalmatze.de/" echo "========= GIT CHECKOUT =========" GIT_WORK_TREE=$path git checkout -f master echo "============= DONE ============="
Save and exit the editor.
Don't forget to change the file permissions to be executable.
$ chmod u+x hooks/post-receive
At last we need to link metalmatze.de to our folder where we deployed metalmatze.de's into.
$ cd /var/www/virtual/metalmatze $ ln -s html/metalmatze.de/public/ metalmatze.de
Now go on metalmatze.de with your browser and check out your automatically deployed website!
Isn't that awesome?!
We are now able to deploy our changes with only one git command, or even with a GUI.
Do you have any questions or comments? Please leave them below. Thanks!