Git for Administrators
An alternative way to maintaining your Moodle server via CVS is using Git. This page describes how to maintain a copy of Moodle on your production server which can easily be upgraded using Git. If you have customisations of Moodle core code, you are advised to follow the instructions in the Quick Git start guide for Moodle development.
Obtaining the code from Git
You can find the official Moodle git repository at git://git.moodle.org/moodle.git (with an official clone at git://github.com/moodle/moodle.git). To initialize your local checkout, use
git clone git://git.moodle.org/moodle.git (1) cd moodle git branch -a (2) git branch --track local_19_STABLE origin/MOODLE_19_STABLE (3) git checkout local_19_STABLE (4)
The command (1) initializes the new local repository as a clone of the upstream moodle.git repository. By default, this upstream repository will be known as 'origin' remote repository. The command (2) lists all available branches. Use the command (3) to create a new local branch called local_19_STABLE and set it to track the branch MOODLE_19_STABLE from the upstream repository. The command (4) actually switches to the newly created local branch. Note that the last two lines can be replaced with
git checkout -b local_19_STABLE origin/MOODLE_19_STABLE (3 + 4)
that creates a new local tracking branches and switches to it immediately.
Updating your installation
The Moodle development team performs integration and testing of fixed bugs every Monday and Tuesday. On Wednesday you can install all patches by updating your code. Check the shortlog to see if the official repository has been already updated or not.
cd /path/to/your/moodle/checkout git fetch (1) git status (2) git merge (3)
The command (1) downloads new updates from the remote repository without touching your local checkout. The command (2) displays the information about the eventual drift between you local version and the upstream one. The command (3) actually modifies your local files with the updates. The git-fetch + git-merge couple can be replaced with a single command
git pull (1 + 3)
Installing a contributed extension from its Git repository
For example, let us say we want to install the Book module form its Git repository into our Moodle 2.0.
cd /path/to/your/moodle/checkout cd mod (1) git clone git://github.com/skodak/moodle-mod_book.git book (2) cd book git checkout -b MOODLE_20_STABLE origin/MOODLE_20_STABLE (3) git branch -d master (4)
The command (1) changes the current directory into the mod folder of your local Moodle clone. The command (2) creates a new subdirectory book and makes a local clone of Petr Škoda's vanilla Book repository. The command (3) creates a new local branch that will track the remote branch with a Book version for Moodle 2.0. The command (4) deletes the master that was created automatically by git-clone in (2) as we do not want it in this production checkout.
Now it is wise to put the new directory mod/book/ to the list of ignored files of the main Moodle clone.
cd /path/to/your/moodle/checkout echo /mod/book/ >> .git/info/exclude
To update your Moodle installation now, you must visit both Git repositories and pull changes from upstream.
cd /path/to/your/moodle/checkout git pull cd /path/to/your/moodle/checkout/mod/book git pull
Writing a shell script with these lines in the root of Moodle installation is a very good idea. Otherwise it is easy to forget what Git repositories are there within the main Moodle repository.
See also
- Moodle Docs
- Moodle forum discussions
- GIT help needed
- Best way to manage CONTRIB code with GIT
- Handy Git tip for tracking 3rd-party modules and plugins
- Moodle Git repositories
- External resources