Note: You are currently viewing documentation for Moodle 2.0. Up-to-date documentation for the latest stable version is available here: Git for Administrators.

Git for Administrators: Difference between revisions

From MoodleDocs
 
(19 intermediate revisions by 10 users not shown)
Line 3: Line 3:
== Obtaining the code from Git ==
== 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
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://github.com/moodle/moodle.git                   (1)
     git clone git://git.moodle.org/moodle.git                       (1)
     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 local_20_STABLE --track origin/MOODLE_20_STABLE      (3)
    git checkout local_20_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, known as the ''origin'' remote repository by default. It creates a new directory named ''moodle'', where it downloads all the files. This operation can take a while.
* The command (2) lists all available branches.
* Use the command (3) to create a new local branch called local_20_STABLE and set it to track the branch MOODLE_20_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_20_STABLE --track origin/MOODLE_20_STABLE        (3 + 4)
 
that creates a new local tracking branch and switches to it immediately.
 
The ''master'' local branch, automatically created by git-clone, can then be deleted with the command
 
    git branch -d master


== Updating your installation ==
== Updating your installation ==
Line 17: Line 29:


     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 ==
 
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


== Important note ==
To update your Moodle installation now, you must visit both Git repositories and pull changes from upstream.


At the moment, the master branch represents Moodle 2.0.x stable code. It is wise to do a <code>git branch -a</code> before a <code>git pull</code> to check whether Moodle 2.0 isn't branched. If Moodle 2.0 gets branched and you are still on master, you will be updating to the latest development version, which is not desirable on a production server. This is an exception caused by the transition from CVS to Git and should never happen again.
    cd /path/to/your/moodle/checkout
    git pull
    cd /path/to/your/moodle/checkout/mod/book
    git pull


== Using a GUI ==
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.
[TODO]


== See also ==
== See also ==
; Moodle Docs
* [[Git FAQ]]
* [[CVS for Administrators]]
* [[CVS for Administrators]]
* [[Moodle versions]]
* For some screenshots see [[User:Frank_Ralf/Git]] (still work in progress)
; Moodle forum discussions
* [http://moodle.org/mod/forum/discuss.php?d=168094 GIT help needed]
* [http://moodle.org/mod/forum/discuss.php?d=165236 Best way to manage CONTRIB code with GIT]
* [http://moodle.org/mod/forum/discuss.php?d=167063 Handy Git tip for tracking 3rd-party modules and plugins]
* [http://moodle.org/mod/forum/discuss.php?d=167730 Moodle Git repositories]
* [http://moodle.org/mod/forum/discuss.php?d=183693 Git and CVS]
; External resources
* [http://www.kernel.org/pub/software/scm/git/docs/everyday.html Everyday GIT With 20 Commands Or So]
* [http://gitref.org/ Git Reference]
* [http://progit.org/book/ Pro Git book]


[[Category:Git]]
[[Category:Git]]
[[Category:Administrator]]
[[Category:Administrator]]
[[ja:管理者用Git]]

Latest revision as of 21:13, 29 January 2014

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 local_20_STABLE --track origin/MOODLE_20_STABLE      (3)
   git checkout local_20_STABLE                                    (4)
  • The command (1) initializes the new local repository as a clone of the upstream moodle.git repository, known as the origin remote repository by default. It creates a new directory named moodle, where it downloads all the files. This operation can take a while.
  • The command (2) lists all available branches.
  • Use the command (3) to create a new local branch called local_20_STABLE and set it to track the branch MOODLE_20_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_20_STABLE --track origin/MOODLE_20_STABLE         (3 + 4)

that creates a new local tracking branch and switches to it immediately.

The master local branch, automatically created by git-clone, can then be deleted with the command

   git branch -d master

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
External resources