Difference between revisions of "Git for Administrators"

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: Git for Administrators.

m (Installing a contributed extension from its Git repository: Trivial typo fix)
m (Improving the example commands)
Line 8: Line 8:
 
     cd moodle
 
     cd moodle
 
     git branch -a                                                  (2)
 
     git branch -a                                                  (2)
     git checkout -b MOODLE_19_STABLE origin/MOODLE_19_STABLE       (3)
+
     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. The command (2) lists all available branches. Use the command (3) to switch to a different branch than the default 'master'.
+
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 ==
 
== Updating your installation ==
Line 17: Line 22:
  
 
     cd /path/to/your/moodle/checkout
 
     cd /path/to/your/moodle/checkout
     git pull
+
    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 ==
 
== Installing a contributed extension from its Git repository ==
Line 46: Line 57:
 
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.
 
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.
  
== Important note ==
+
== See also ==
 
 
For pretty long time, the Moodle 2.0.x stable code lived on ''master'' branch instead of ''MOODLE_20_STABLE''. Moodle 2.0 was then branched but if you stayed on master, you would update to the latest development version, which is not desirable on a production server. This was an exception caused by the transition from CVS to Git and should never happen again.
 
 
 
== Using a GUI ==
 
[TODO]
 
  
== See also ==
 
 
* [[CVS for Administrators]]
 
* [[CVS for Administrators]]
 +
* [[Moodle versions]]
  
 
[[Category:Git]]
 
[[Category:Git]]
 
[[Category:Administrator]]
 
[[Category:Administrator]]

Revision as of 11:32, 1 April 2011

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 and git://github.com/moodle/moodle.git. To initialize your local checkout, use

   git clone git://github.com/moodle/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
   cat /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