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

Git for Administrators: Difference between revisions

From MoodleDocs
(ja link)
 
(21 intermediate revisions by 14 users not shown)
Line 1: Line 1:
An alternative way to maintaining your Moodle server via [[CVS for Administrators|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 [[Development:Quick Git start guide for Moodle development|Quick Git start guide for Moodle development]].
{{Installing Moodle}}
The recommended way (now all Moodle development has moved to this versioning system) is 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 [[Development:Quick Git start guide for Moodle development|Quick Git start guide for Moodle development]].


== Obtaining the code from Git ==
To get the most of of Git it is worth making the effort to understand its basic concepts - see the See also section below. It can be a bit of a learning curve, especially if you are used to CVS or Subversion.


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
== Getting hold of Git (Windows, OSX, Linux and others) ==


    git clone git://git.moodle.org/moodle.git                      (1)
Support for Git was, up until recently, mostly confined to Linux but builds are now available for most popular operating systems:
    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
* List of downloads from Git site - http://git-scm.com/download


    git checkout -b local_19_STABLE origin/MOODLE_19_STABLE        (3 + 4)
Once you have downloaded and installed your OS relevant git installation, the git commands in this document should work with your operating system.


that creates a new local tracking branches and switches to it immediately.
== Obtaining the code from Git ==


== Updating your installation ==
The command line version of Git is discussed here. Graphical clients are little more than wrappers around the command line version, so you should be able to deduce the correct parameters quite easily.


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 [http://git.moodle.org/gw?p=moodle.git;a=summary shortlog] to see if the official repository has been already updated or not.
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
<pre>
$ git clone git://git.moodle.org/moodle.git                       (1)
$ cd moodle
$ git branch -a                                                   (2)
$ git branch --track MOODLE_23_STABLE origin/MOODLE_23_STABLE      (3)
$ git checkout MOODLE_23_STABLE                                    (4)
</pre>
* The command (1) initializes the new local repository as a clone of the 'upstream' (i.e. the remote server based) moodle.git repository. The upstream repository is called 'origin' by default. It creates a new directory named ''moodle'', where it downloads all the files. This operation can take a while as it is actually getting the entire history of all Moodle versions
* The command (2) lists all available branches.
* Use the command (3) to create a new local branch called MOODLE_23_STABLE and set it to track the remote branch MOODLE_23_STABLE from the upstream repository.
* The command (4) actually switches to the newly created local branch.  


    cd /path/to/your/moodle/checkout
Note that Git has a huge number of options for each command and it's actually possible to do the above process with a single command (left as an exercise!!).
    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 from behind a firewall==


    git pull                                                        (1 + 3)
Git uses a proprietary protocol and it may be blocked by your firewall (port 9418). If this is a problem, you can use Github's http version <nowiki>https://github.com/moodle/moodle.git</nowiki>. It's a bit slower, so use the Git protocol if you can.


== Installing a contributed extension from its Git repository ==
== Updating your installation ==


For example, let us say we want to install the [[Book module]] form its Git repository into our Moodle 2.0.
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 [http://git.moodle.org/gw?p=moodle.git;a=summary shortlog] to see if the official repository has been already updated or not.


    cd /path/to/your/moodle/checkout
To update your code to the latest version (on the MOODLE_22_STABLE branch) '''all''' you have to do is:
    cd mod                                                          (1)
<pre>
    git clone git://github.com/skodak/moodle-mod_book.git book      (2)
$ cd /path/to/your/moodle/
    cd book
$ git pull
    git checkout -b MOODLE_20_STABLE origin/MOODLE_20_STABLE        (3)
</pre>
    git branch -d master                                            (4)
If this is a production site you should still consider the [[Upgrade]] instructions (e.g. take backups).


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.
== Installing a contributed extension from its Git repository ==


Now it is wise to put the new directory mod/book/ to the list of ignored files of the main Moodle clone.
This is one way to handle adding plugins from other Git repositories into your Moodle repository. Another way is to use Git Submodules. However, at the time of writing, this is one of Git's rougher features and should be regarded as an advanced option.  


    cd /path/to/your/moodle/checkout
For example, let us say we want to install the [[Book module]] from its Git repository into our Moodle 2.2.
    echo /mod/book/ >> .git/info/exclude
<pre>
$ cd /path/to/your/moodle/
$ cd mod                                                                        (1)
$ git clone -b MOODLE_22_STABLE git://github.com/skodak/moodle-mod_book.git book (2)
</pre>
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, using the appropriate branch.


Now it is wise to put the new directory mod/book/ to the list of ignored files of the main Moodle clone, otherwise a status of the main clone will keep reminding you that the new code has not been checked in.
<pre>
$ cd /path/to/your/moodle/
$ echo /mod/book/ >> .git/info/exclude
</pre>
To update your Moodle installation now, you must visit both Git repositories and pull changes from upstream.
To update your Moodle installation now, you must visit both Git repositories and pull changes from upstream.
 
<pre>
    cd /path/to/your/moodle/checkout
$ cd /path/to/your/moodle/
    git pull
$ git pull
    cd /path/to/your/moodle/checkout/mod/book
$ cd mod/book
    git pull
$ git pull
 
</pre>
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.


Line 60: Line 75:


; Moodle Docs
; Moodle Docs
* [[CVS for Administrators]]
* [[Git FAQ]]
* [[Windows installation using Git]]
* [[Moodle versions]]
* [[Moodle versions]]
* For some screenshots see [[User:Frank_Ralf/Git]] (still work in progress)
* For some screenshots see [[User:Frank_Ralf/Git]] (still work in progress)
* For fixing a Tracker Issue (MDL) / Forking Moodle / CONTRIButing code ... [[User:Sam_Hemelryk/My_Moodle_Git_workflow]]
* [[Moodle_Production_Server_with_GIT|Case study Git + Moodle from Technical University Berlin]]


; Moodle forum discussions
; Moodle forum discussions
* [https://moodle.org/mod/forum/discuss.php?d=213695 Got GIT installed on my site- here's how!]
* [http://moodle.org/mod/forum/discuss.php?d=168094 GIT help needed]
* [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=165236 Best way to manage CONTRIB code with GIT]
Line 70: Line 89:
* [http://moodle.org/mod/forum/discuss.php?d=167730 Moodle Git repositories]
* [http://moodle.org/mod/forum/discuss.php?d=167730 Moodle Git repositories]
* [http://moodle.org/mod/forum/discuss.php?d=183693 Git and CVS]
* [http://moodle.org/mod/forum/discuss.php?d=183693 Git and CVS]
* [http://moodle.org/mod/forum/discuss.php?d=208904 GIT for dummies]
* [http://moodle.org/mod/forum/discuss.php?d=211930 Git and upgrading misunderstanding]


; External resources  
; External resources  
Line 75: Line 96:
* [http://gitref.org/ Git Reference]
* [http://gitref.org/ Git Reference]
* [http://progit.org/book/ Pro Git book]
* [http://progit.org/book/ Pro Git book]
 
* [http://eigenjoy.com/2008/05/15/git-from-the-bottom-up/ Git from the bottom up]
 
[[Category:Git]]
[[Category:Administrator]]


[[ja:管理者用Git]]
[[ja:管理者用Git]]
[[fr:Git_pour_administrateurs]]

Latest revision as of 17:56, 31 January 2013

The recommended way (now all Moodle development has moved to this versioning system) is 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.

To get the most of of Git it is worth making the effort to understand its basic concepts - see the See also section below. It can be a bit of a learning curve, especially if you are used to CVS or Subversion.

Getting hold of Git (Windows, OSX, Linux and others)

Support for Git was, up until recently, mostly confined to Linux but builds are now available for most popular operating systems:

Once you have downloaded and installed your OS relevant git installation, the git commands in this document should work with your operating system.

Obtaining the code from Git

The command line version of Git is discussed here. Graphical clients are little more than wrappers around the command line version, so you should be able to deduce the correct parameters quite easily.

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 MOODLE_23_STABLE origin/MOODLE_23_STABLE      (3)
$ git checkout MOODLE_23_STABLE                                    (4)
  • The command (1) initializes the new local repository as a clone of the 'upstream' (i.e. the remote server based) moodle.git repository. The upstream repository is called 'origin' by default. It creates a new directory named moodle, where it downloads all the files. This operation can take a while as it is actually getting the entire history of all Moodle versions
  • The command (2) lists all available branches.
  • Use the command (3) to create a new local branch called MOODLE_23_STABLE and set it to track the remote branch MOODLE_23_STABLE from the upstream repository.
  • The command (4) actually switches to the newly created local branch.

Note that Git has a huge number of options for each command and it's actually possible to do the above process with a single command (left as an exercise!!).

Git from behind a firewall

Git uses a proprietary protocol and it may be blocked by your firewall (port 9418). If this is a problem, you can use Github's http version https://github.com/moodle/moodle.git. It's a bit slower, so use the Git protocol if you can.

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.

To update your code to the latest version (on the MOODLE_22_STABLE branch) all you have to do is:

$ cd /path/to/your/moodle/
$ git pull

If this is a production site you should still consider the Upgrade instructions (e.g. take backups).

Installing a contributed extension from its Git repository

This is one way to handle adding plugins from other Git repositories into your Moodle repository. Another way is to use Git Submodules. However, at the time of writing, this is one of Git's rougher features and should be regarded as an advanced option.

For example, let us say we want to install the Book module from its Git repository into our Moodle 2.2.

$ cd /path/to/your/moodle/
$ cd mod                                                                         (1)
$ git clone -b MOODLE_22_STABLE git://github.com/skodak/moodle-mod_book.git book (2)

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, using the appropriate branch.

Now it is wise to put the new directory mod/book/ to the list of ignored files of the main Moodle clone, otherwise a status of the main clone will keep reminding you that the new code has not been checked in.

$ cd /path/to/your/moodle/
$ 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/
$ git pull
$ cd 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