If you’re a Moodle admin who doesn’t use Git, you’re missing out.
Every Moodle developer knows how to use Git. The core Moodle project and the vast majority of plugin repositories are hosted on GitHub, so Git is clearly a crucial tool for developers. But in my experience, Moodle admins — even folks who run Moodle sites on their own web and database servers — don’t typically use Git.
I understand why. Git can be frustratingly opaque at first. It may not be clear what advantages one gets from using Git as an admin since there is not typically a need to directly modify and version control Moodle code. It also requires the use of the command line, which can be a deterrent for some. In fact, I may never have started using it but for the fact that I took over as admin for a production Moodle site with a great Git workflow already set up. It had a steep learning curve, but once I got more comfortable using it and appreciating it’s powerful features I grew to consider Git an essential admin tool.
This is the first in a series of posts in which I’ll share some basic Git workflows for Moodle admins. Why should you follow along? Here are some of the things you can learn to do with Git with Moodle admin-focused tutorials:
- Increase the speed at which you deploy or update Moodle code
- Easily manage code for sites with many plugins
- Keep a backup of your customized Moodle codebase
- Enable an efficient SSH workflow for updates
- Apply the exact same changes to multiple servers at once or automatically deploy code with scripts (this is particularly needed if you run a cluster of Moodle servers or want to run Moodle in the cloud)
Excited? Before we get started:
- Make sure to install Git on your computer
- Bookmark the Git documentation or grab a copy of the Open Source Git Pro eBook
- Have access to a command-line application. The built-in terminal on any Mac or Linux computer will work fine. If you are on Windows 10 and don’t have a terminal app, you can download the new Windows Terminal.
- For later posts, you’ll need to set up a GitHub account
Let’s get started with a simple exercise that highlights the speed and efficiency of Git.
Deploying Moodle Code with Git
Instead of downloading the core Moodle files, unzipping, them, then manually uploading them to a server, we’ll grab them in one quick Git action. Open your terminal app and enter the following command (note that depending on your system you may need to preface these commands with sudo):
git clone -b MOODLE_35_STABLE https://github.com/moodle/moodle.git mymoodleinstall
You should see Git doing its thing. It will create a folder called “mymoodleinstall” and download the latest release of Moodle 3.5.
So what did you just type?
- git invokes the application
- clone is the Git command to download a copy of a repository
- -b is an option you can pass to the clone command to specify that you want a particular branch of the repository, in our case for Moodle 3.5
- The URL is the location of the Moodle Github repository
- mymoodleinstall is a random name we chose as the local location for our copy of the repository. You can use whatever name you want.
Now go into the mymoodleinstall folder and type another git command:
You should see the following output:
On branch MOODLE_35_STABLE
Your branch is up to date with 'origin/MOODLE_35_STABLE'.
nothing to commit, working tree clean
Updating Moodle with Git
The bit about branches means that you have a Git repository that is going to be super easy to keep up to date with the latest code for your version of Moodle (in this case the version was 3.5, but we could have created a branch for any Moodle release). You can type a simple command to get the latest update from your current branch (since you just downloaded the latest version, you should just see a message that you’re already up to date):
In this post, you learned how to save time and effort by downloading and updating your Moodle code with a few simple commands. Next time, we’ll see how to continue to pull updates from the official Moodle source and then push our custom code to our own GitHub repo.