Obsolete:Tutorial on using git in Moodle development
Disclaimer: This is not a tutorial on git itself. You are supposed to know the basic concepts of git (notably cloning, branching and merging). This tutorial is based on my personal experience with using git in Moodle development process. There are other (and almost certainly better) ways of doing it. See the references at the bottom of the page. Quite often, I found a solution that just worked and did not explore alternatives. You are warmly welcome to contribute and improve this tutorial. Please use the talk page to add/fix something so I can merge it into the tutorial text. --David Mudrak
Preparing the environment
In this tutorial, we will use the following environment. Check the diagram. At the moment, there are two source code repositories you can use: the main Moodle CVS server cvs.moodle.org and its git mirror at git.moodle.org. While the CVS contains both Moodle core code and the contributed code, the git mirrors the core code only yet (this may be changed in the near future). We also expect you have some server (we will call it "nostromo") that you and your team members use and that you do the actual developing at the localhost machines.
Later in this tutorial, you will see how
git fetch
can be used to get the recent changes from upstream to nostromogit cvsimport
can be used to create your own git mirror of a contributed code (we do not do this yet for you)git clone
can be used to create a mirror of your nostromo repos at you local machinesgit push
can be used to backup your own work and to share it with your friendgit pull
can be used regularly to fetch and merge the work done by your friendgit cvsexportcommit
can be used to send your commits for the upstream (and you will, right? ;-)
Create your own Moodle source codes mirror
Make sure you and your team friends have write access to /pub/scm/git
at your nostromo server.
$ ssh nostromo $ cd /pub/scm/git $ mkdir moodle.git $ cd moodle.git $ git init --bare
That will create an empty bare repository in /pub/scm/git/moodle.git directory. Shortly, the "bare" means it contains just the repository itself, not the working copy (checkout) of the files.
$ git --bare fetch git://git.moodle.org/moodle.git cvshead:cvshead $ git --bare fetch git://git.moodle.org/moodle.git MOODLE_19_STABLE:MOODLE_19_STABLE $ git --bare fetch git://git.moodle.org/moodle.git MOODLE_18_STABLE:MOODLE_18_STABLE
These three commands will create three branches - cvshead, MOODLE_19_STABLE and MOODLE_18_STABLE from the upstream and will fetch all the Moodle development history. You can re-run the same commands later to fetch the recent changes. They can be run by cron to regularly fetch the latest changes from the upstream to your nostromo repository. It makes sense to run theme every 30 minutes as it is the interval of the git.moodle.org updates.
Check out the working copies of the repository
Now let us go to your localhost machine and check out the working copy from the nostromo repository
$ cd ~/public_html $ git clone ssh+git://nostromo/pub/scm/git/moodle.git moodle19 $ cd moodle19 $ git checkout -b MOODLE_19_STABLE origin/MOODLE_19_STABLE
After these commands, you have a checkout of the latest 1.9.x Moodle branch in your ~/public_html/moodle19
. To update it (it est to fetch the changes from your nostromo and to merge them), just run
$ git pull
Prepare a customized branch for your client
Imagine your are going to install and customize Moodle 1.9 for a client, for example the Hogwarts School. Let us create a branch for them where the whole customization will be done.
$ cd ~/public_html/moodle19 $ git checkout -b mdl19-hogwarts origin/MOODLE_19_STABLE $ ... (do all your customization here, git add, git commit etc)
Now, publish your changes to nostromo so your friend can clone it. Also, pushing your stuff to a server is quite a good backup of your work.
$ git push origin mdl19-hogwarts:mdl19-hogwarts
Later on, just git push
should be enough as the remote branch already exists but this depends on your git settings.
Your friend can make their own clone of your customizations with
$ cd ~/public_html/moodle19 $ git checkout -b mdl19-hogwarts origin/mdl19-hogwarts $ ... (hack something, git add, git commit) $ git push
Deploying a customized branch
With a shell access to the client's webhost
If you can, install git at the client's webhost. Then you can just create another clone of your customer's branch using the same commands as when you did during the checking out to your development machine.
With FTP access only
$ cd ~/public_html/moodle19 $ git checkout mdl19-hogwarts $ git pull $ git tag mdl19-hogwarts-20091026 $ git archive --format=tar --prefix=hogwarts/htdocs/ mdl19-hogwarts-20091026 | (cd /tmp/ && tar xf -)
Now you can upload /tmp/hogwarts/htdocs/
to the server
Appendix
Credits
A big thank you to Penny, Dan and Nigel for helping me with my first steps with git.