My GIT Routine
Let’s say I had a new idea for a WordPress plugin, I can’t wait to start writing, so the setup of the GIT environment should be as fast as possible. That’s where my setup will come in handy. Let’s open the terminal, I’ll go inside my testing directory and from there I’ll run:
ssh git_ssh 'create awesomePlugin' creating project "awesomePlugin.git" Initialized empty Git repository in /var/git/awesomePlugin.git/ All done, you can now work on "awesomePlugin.git"
The project is created, now I just need to clone it
git clone ssh://git_ssh:/var/git/awesomePLugin.git Cloning into 'awesomePlugin'... warning: Looks like you cloned an empty repository.
And that’s it, I now have a local and a remote copy of my git repository ready to work with.
Let’s say I’m working on this plugin and I get to the point where I feel like I can use it on my own blog, I want the deploy to be as fast as the rest of the process was, so I’ll ssh as my normal user and modify the
deploy.sh script inside the
custom-hooks directory for this project to add the working directory and the branch I want to use for deploy (you can use master, but it’s better to use a different branch only for this pourpose, this way you can keep the production code stable and use master for experimenting until ready to deploy)
Inside the deploy.sh script I’ll edit those 2 lines:
# Directory where to deploy files from repository DPTARGET="" # Branch that is going to be deployed to server DPBRANCH="master"
DPTARGET and “production” as
now on my local system I’ll add a new branch and use that before committing my stable code.
git checkout -b production Switched to a new branch 'production' git add . git commit -m "awesomePlugin is even more awesome" [production (root-commit) a3885a4] awesomePlugin is even more awesome 1 file changed, 1 insertion(+) create mode 100644 awesomePlugin.php git push origin production Counting objects: 3, done. Writing objects: 100% (3/3), 240 bytes | 240.00 KiB/s, done. Total 3 (delta 0), reused 0 (delta 0) remote: Ref refs/heads/production received. Deploying production branch to production... remote: /=============================== remote: | DEPLOYMENT COMPLETED remote: | Target branch: /var/www/htdocs/wp-content/plugins/awesomePlugin remote: | Target folder: /var/git/awesomePlugin.git remote: | Tag name : release_12072018-1110 remote: \============================== To ssh://git_ssh:/var/git/awesomePlugin.git * [new branch] production -> production
And that’s it, now my new plugin is ready to go live as soon as I activate it inside my WordPress admin area.
That’s it for now, I’ll add to this post as soon as I decide whether I want my code to be visible or not, but for now this is my setup and it’s working greatly for me so far.
If you made it this far I hope you’ll spend a couple more minutes to let me know what you think about this setup, if you use something similar or if you had any problems setting this up, I’ll try and help you as much as I can of course.