Setting Up A Git Repository On Dreamhost For My WordPress Theme
For any Dreamhost questions, I always refer to the Wiki which is excellently compiled. However, I realised that the Wiki has either an outdated answer or simply failed to answer the question of “How to set up a Git Repository on your Dreamhost account”. Thus you can sort of ignore this page on the Wiki.
My goal is to set up a private repository for my own WordPress theme, so that I’ll have version control and a complete change log for all developmental work on the theme. Another benefit in this is that I can sync the theme easily with my WordPress install, without having to do any FTP uploads (while figuring out which files were changed).
To set up Git repositories on Dream is actually quite easy, and I’ll recount how I did it. In the shell code examples below, USER refers to your user name on Dreamhost, while EXAMPLE.COM refers to your domain.
Step 1: Create A Dreamhost Repository
Firstly, I created a sub-domain to store my repositories, and I used .htaccess to protect it from the general public.
Both of these can be done from the Dreamhost Panel by following these two wikis:
1. Adding A Subdomain To Your Dreamhost Account
2. Configuring .htaccess
Then I entered shell, browsed to the sub-domain which I created in the step above, and created an empty repository with these commands:
$ mkdir my_wp_theme.git $ cd my_wp_theme.git $ git --bare init $ git --bare update-server-info
Step 2: Create A Local Repository
Next, I created a local repository on my development machine, which will be later published to the Dreamhost repository.
$ mkdir my_wp_theme $ cd my_wp_theme $ git init
Configure the local repository with the Dreamhost repository details.
$ git config push.default matching $ git remote add origin ssh://USER@EXAMPLE.COM/home/USER/SUB.EXAMPLE.COM/my_wp_theme.git $ git config branch.master.remote origin $ git config branch.master.merge refs/heads/master
Step 3: Push The Contents
Following which, I copied over my WordPress theme files into this local repository. Then I added, committed and pushed my changes.
$ git add . $ git commit -m "Initialization." $ git push --all $ git pull
Step 4: Sync With WordPress Install
To sync with my WordPress install, I browsed to <wordpress>/wp-content/themes and cloned the repository.
git clone ssh://USER@EXAMPLE.COM/home/USER/SUB.EXAMPLE.COM/my_wp_theme.git
Then I went into the WordPress Admin and activated this gitorised theme. Done!
In the future, when I am finished with any changes to my theme, all I have to do is: Push my changes, then pull the changes on the server.
winston.yongwei