Andy Vaughn

Git Started

Using a version control system is helpful for multiple developer environments, as well as individual tracking and archiving of changes. Here’s how I set mine up using Git.

Note: Setting up a cloned repository between dev and live servers is useful for theme and static file tracking. You wouldn’t want to setup Git on an entire WordPress directory, however, because tracking uploaded files from the live site “Uploads” folder would cause tracking problems. For WordPress, specifically, I like to setup Git inside my custom theme directory, where files will not likely be changed on the live website.

Initialize Git on your remote server

  1. SSH into your remote server: $ ssh <username>@<host>
  2. CD to the theme directory: $ cd www/wp-content/themes/<custom_theme_name>
  3. Initialize Git: $ git init
  4. Add the current files (if any): $ git add .
  5. Commit the addition: $ git commit -m "Initial Commit"

Clone a bare repository outside the web root

  1. $ git clone --bare /home/<username>/www/wp-content/themes/>custom_theme_name> /home/<username>/proj.git

Clone the bare repository to your local server

  1. CD to your local server directory. Mine is in MAMP htdocs: $ cd /Applications/MAMP/htdocs/
  2. Create a dev directory by cloning the remote repository: $ git clone ssh://<username>@<host>/home/<username>/proj.git <custom_theme_name>

This will create a local copy of your remote server files. Now you can make changes to these files and keep track of them using Git.

Add, edit, save your local files.

  1. Create a dev branch: $ git branch dev
  2. Checkout the dev branch: $ git checkout dev
  3. Make changes, edits, save files.
  4. Add them to Git.: $ git add .
  5. Commit the changes: $ git commit -m "Made changes"
  6. Checkout the master branch: $ git checkout master
  7. Pull changes from the origin, to see if any changes have been made (if working in a multiple developer environment): $ git pull origin
  8. Resolve any conflicts in code.
  9. Merge the dev and master branch: $ git merge dev
  10. Push the changes to the remote repository: $ git push origin

Pull changes to live website

  1. SSH into remote server
  2. CD to theme directory: $ cd www/wp-content/themes/<custom_theme_name>
  3. Pull new files and edits from the repository: $ git pull /home/<username>/proj.git

And, voila! You have a working repository environment using Git to track changes to your custom WordPress theme, or other static file directory.

Any questions?

Git Resources

Posted by Andy Vaughn on April 5, 2010

Leave a Comment