Maintaining Moodle customisations with Git

Jump to: navigation, search

Note: You are currently viewing documentation for Moodle 1.9. Up-to-date documentation for the latest stable version is available here: Maintaining Moodle customisations with Git.

This page is a work in progress

Git makes it very easy to maintain local customisations to Moodle alongside updates from the official Moodle repository. This page assumes you installed Moodle following Installing Moodle from Git repository. It also assumes you understand basic version control principles (repositories, branches, conflicts) and have a basic working knowledge of Git.

First, from your moodle directory, create a branch of master which will contain your customised Moodle. This is the branch you'll publish to other servers.

git checkout master
git checkout -b mycustommoodle
Switched to a new branch 'mycustommoodle'

Next, create a new branch for developing your customisation, and move to that branch:

git checkout -b myfeature
Switched to a new branch 'myfeature'

This will give you a seperate copy of the Moodle code to work on without affecting the master branch. It's not recommended that you do this on your production server, as it will cause the code to be available immediately as it's saved.

Do your customisations, add any new files to git, and commit the changes

git add .
git status
git commit -m "Description of the change"

Switch back to the mycustommoodle branch and merge the changes

git checkout mycustommoodle
git merge myfeature

Any future development can take place on the myfeature branch, and be merged into mycustommoodle in this way

Even after local modifications have been made, you can pull in updates from the official git repository

git checkout master
git fetch
git merge origin/master
git checkout mycustommoodle
git merge master


If you create a local modification to a file, and that same file is modified in the official repository, you may find that a conflict is created when you do git merge origin/master.

To resolve this, you will need to find the conflicts (the attempt to merge will tell you where they are) and resolve them. The git merge man page has more information on the presentation and resolution of conflicts.

After the conflict is resolved, you'll need to commit the resolved files.

git commit -a

Once a conflict has been resolved, even if you keep your local modification over the upstream modification, there wont be a conflict next time you merge.