GIT – how to setup your own server

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 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 script I’ll edit those 2 lines:

# Directory where to deploy files from repository
# Branch that is going to be deployed to server

adding /var/www/wp-content/plugins/awesomePlugin as DPTARGET and “production” as DPBRANCH.

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:    | 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.

Danilo M.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>


This site uses Akismet to reduce spam. Learn how your comment data is processed.