Category Archives: GIT

Useful GIT commands

I’ll use this post as a personal reference for useful GIT commands as I find them. Hopefully they’ll help you also.

Scenario #1

You have accidentally made a few commits to a branch and you wish to undo them so they are identical to the origin. You’ll probably see something like this when you run git status

# On branch devel
# Your branch is ahead of ‘origin/devel’ by 2 commits.


git reset --hard origin/

This resets your current branch to an identical state of the current HEAD of the origin <branch>

Scenario #2

You have created a branch B from branch A and made a few commits. Assuming you write useful commit messages it’s useful for other developers to see the changes you’ve made and the features you’ve added since you branched. To do this type the following command:

git log $(git merge-base A B)..B #

Scenario #3

List all branches, ordered by last-commit date (with last-commit date visible):

for k in `git branch|perl -pe s/^..//`;do echo -e `git show –pretty=format:”%Cgreen%ci %Cblue%cr%Creset” $k|head -n 1`\\t$k;done|sort -r

WordPress plugin deployment script (GIT to SVN)

Short Version: This script will allow you to manage your wordpress plugins in git, and deploy them to SVN.

Long Version:

Recently at work I was required to build a wordpress plugin. After trawling through the documentation to figure out what I needed to do, it became apparent that to get my plugin listed in the WordPress plugins directory I would be required to host the code in their SVN repository. Along with most developers nowadays, I’ve switched to Git (for numerous reasons), so I was left with the dilemna of how to manage my plugin within git and host it on Github, but sync all changes to the SVN repository whenever a new version was ready. There’s quite a lot of work involved when trying to do this so I wanted to automate the whole thing. The result is a bash script shown below which will:

  1. Check that the version numbers in your readme.txt match up with those in your PHP file.
  2. Commit the latest outstanding changes to your git repository if any are left
  3. Push the latest changes to github
  4. Export the contents at the HEAD of your ‘master’ branch in git to the trunk of your SVN repository.
  5. Commit the changes to SVN and therefore push them  back to
  6. Create an SVN tag for to use and commit it (this will be the same value as Stable Tag: <tagnumber> in your readme.txt)
  7. Update the version number for future reference.

Hopefully this should make life a little easier for those WordPress plugin developers who wish to manage their projects in GIT :)

Download the script here