When you are working with Git, the general workflow is use some kind of version control that helps you deploy a site in the this case. You have a local repository where you work and a remote repository where you keep everything in sync, but you can use Git to move your project into your production when you are ready.
The way I have setup in most case, I will have a repository that is pre-created so that I can just push my work into my production server rather than having to delete the old project and copy the newer version every time. All working process/progress will be done in github where I do all my changes and commits and pushes to GitHub, while the production only gets push so it gets changes.
In most cases, the directory that you want to setup can be added anywhere in your server ( VPS or Dedicated Server ) and it usually would be under the following directory.
and your project repository would be somewhere that can’t be seen by other users
Every VPS or Dedicated Server’s main directory that deploys all sites can be different but in my case, my sites and repos would all under the following
As for the repo itself, the way i have it because, this would be similar to how github works, so it would be something like this
but since we are deploying our own then it should be something like this
Working with Hooks
The only thing that we are interested is using post-recieve, but first we will need to do the following so that the repository exist.
When creating a new folder for a git repository, make sure to name it so that when you deploy to a specific site, only that site can only push all changes. You could do something like
mkdir -p /home/username/username/working-directory.git
Please do remember that the working-directory.git is actually a folder and not a file. Navigate to the folder
git init --bare
You will need to type git init –bare so it will initialize a pre-folders that makes the repository accessible, then head over to the hooks folder and you will need to create a post-receive file with the lines
cat > post-receive
When you execute this command, you will have a blank line indicating that everything you type will be saved to this file. so let’s type
git --work-tree=/home/username/public_html/wp-content/themes/working-directory --git-dir=/home/username/username/working-directory.git checkout -f
When finished, press CTRL + D to save and it will then exits. You will then need to change the permissions as well
chmod +x post-recieve
Create a local folder that will contain your files and make sure to use git init so it system can recognized as a repository and we will then need to configured the remote path to the repository that you created.
git remote add live email@example.com:username/working-directory.git
Now you can do your normal daily activities to commit, push and all that neat stuff. To push to the repo, just type
git push -u live master
As for me, I would only push projects instead of committing since that’s what the github repo is for.