Note: You are currently viewing documentation for Moodle 2.5. Up-to-date documentation for the latest stable version of Moodle may be available here: Git for Administrators.

Git for Administrators: Difference between revisions

From MoodleDocs
No edit summary
(→‎See also: link edit)
 
(44 intermediate revisions by 20 users not shown)
Line 1: Line 1:
{{stub}}
{{Installing Moodle}}
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]].


An alternative way for maintaining your Moodle server via [[CVS_for_Administrators]] is using 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.  


==Purpose of this article==
== Getting hold of Git (Windows, OSX, Linux and others) ==
The purpose of this articla is to describe how to maintain a copy of Moodle on your production server, that is easy to upgrade using Git. If you have customisations of Moodle core code, you are advised to follow the instructions on [[Development:Quick_Git_start_guide_for_Moodle_development]]


==Where are the files==
Support for Git was, up until recently, mostly confined to Linux but builds are now available for most popular operating systems:
You can find the official Moodle git repository on git://git.moodle.org/moodle.git and git://github.com/moodle/moodle.git


==Initial download of the Moodle code==
* List of downloads from Git site - http://git-scm.com/download


<code>git clone git://github.com/moodle/moodle.git</code>
Once you have downloaded and installed your OS relevant git installation, the git commands in this document should work with your operating system.


==Moving to the correct version of Moodle==
== Obtaining the code from Git ==
(only if you need something else then master)


* List all existing branches
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.


<code>git branch -a </code>
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_25_STABLE origin/MOODLE_25_STABLE    (3)
$ git checkout MOODLE_25_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_25_STABLE and set it to track the remote branch MOODLE_25_STABLE from the upstream repository.
* The command (4) actually switches to the newly created local branch.


* Move to the desired 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!!).


<code>git checkout BRANCHE_NAME</code>
==Git from behind a firewall==


Now your code base is on the correct version
Git uses a read-only protocol that 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.


==Updating your installation==
== Updating your installation ==


Moodle.com performs testing and integration of fixed bugs every Tuesday, so on Wednesday you can install all patches by updating your code.
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.


<code>git pull</code>
To update your code to the latest version (on the MOODLE_22_STABLE branch) '''all''' you have to do is:
<pre>
$ cd /path/to/your/moodle/
$ git pull
</pre>
If this is a production site you should still consider the [[Upgrade]] instructions (e.g. take backups).


==Important note==
== Installing a contributed extension from its Git repository ==


At the moment, master is Moodle 2.x stable. It is wise to do a <code>git branch -a</code> before a <code>git pull</code> to see 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 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.  


[[Category:Git]]
For example, let us say we want to install the [[Book module]] from its Git repository into our Moodle 2.2.
<pre>
$ cd /path/to/your/moodle/
$ cd mod                                                          (1)
$ git clone git://github.com/skodak/moodle-mod_book.git book      (2)
$ cd book
$ git checkout -b MOODLE_22_STABLE origin/MOODLE_22_STABLE        (3)
$ git branch -d master                                            (4)
</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. The command (3) creates a new local branch that will track the remote branch with a Book version for Moodle 2.2. 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.


Note: you should check first the compatibility of a module with your Moodle branch by asking directly to the Maintainer before cloning the repo or - if you want to guess it - by issueing the command below before running the command (3), in order to verify what is available among the branches:
<pre>
$ git branch -a
* master
  remotes/origin/HEAD -> origin/master
  remotes/origin/MOODLE_15_STABLE
  remotes/origin/MOODLE_17_STABLE
  remotes/origin/MOODLE_18_STABLE
  remotes/origin/MOODLE_19_STABLE
  remotes/origin/MOODLE_20_STABLE
  remotes/origin/MOODLE_21_STABLE
  remotes/origin/MOODLE_22_STABLE
  remotes/origin/master
</pre>
This will avoid an error message when you issue the command (3) against a nonexistent branch, e.g.:
<pre>
§ git checkout -b MOODLE_25_STABLE origin/MOODLE_25_STABLE
fatal: git checkout: updating paths is incompatible with switching branches.
Did you intend to checkout 'origin/MOODLE_25_STABLE' which can not be resolved as commit?
</pre>
In this case you should ask the Mantainer, here Petr Škoda, if ''master'' is the correct branch for Moodle 2.3+ and he will reply that the [[Book module]] has been already integrated in Moodle starting from 2.3 so there's no need to install it usit ''git''. Please, as a general rule, before asking the Mantainer for something you should check the online documentation.


[[Category:Administrator]]
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.
<pre>
$ cd /path/to/your/moodle/
$ git pull
$ cd mod/book
$ 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.
 
== See also ==
 
; Moodle Docs
* [[Git FAQ]]
* [[Windows installation using Git]]
* [[Git for Mac]]
* [[:dev:Moodle versions]]
* 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
* [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=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]
* [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]
* [https://moodle.org/mod/forum/discuss.php?d=231046 Clear git guide for Admins (not developers)]
 
; 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]
* [http://eigenjoy.com/2008/05/15/git-from-the-bottom-up/ Git from the bottom up]
 
[[ja:管理者用Git]]
[[fr:Git_pour_administrateurs]]
[[es:Git para Administradores]]

Latest revision as of 15:14, 16 October 2013

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_25_STABLE origin/MOODLE_25_STABLE     (3)
$ git checkout MOODLE_25_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_25_STABLE and set it to track the remote branch MOODLE_25_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 read-only protocol that 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 git://github.com/skodak/moodle-mod_book.git book      (2)
$ cd book
$ git checkout -b MOODLE_22_STABLE origin/MOODLE_22_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.2. 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.

Note: you should check first the compatibility of a module with your Moodle branch by asking directly to the Maintainer before cloning the repo or - if you want to guess it - by issueing the command below before running the command (3), in order to verify what is available among the branches:

$ git branch -a
* master
  remotes/origin/HEAD -> origin/master
  remotes/origin/MOODLE_15_STABLE
  remotes/origin/MOODLE_17_STABLE
  remotes/origin/MOODLE_18_STABLE
  remotes/origin/MOODLE_19_STABLE
  remotes/origin/MOODLE_20_STABLE
  remotes/origin/MOODLE_21_STABLE
  remotes/origin/MOODLE_22_STABLE
  remotes/origin/master

This will avoid an error message when you issue the command (3) against a nonexistent branch, e.g.:

§ git checkout -b MOODLE_25_STABLE origin/MOODLE_25_STABLE
fatal: git checkout: updating paths is incompatible with switching branches.
Did you intend to checkout 'origin/MOODLE_25_STABLE' which can not be resolved as commit?

In this case you should ask the Mantainer, here Petr Škoda, if master is the correct branch for Moodle 2.3+ and he will reply that the Book module has been already integrated in Moodle starting from 2.3 so there's no need to install it usit git. Please, as a general rule, before asking the Mantainer for something you should check the online documentation.

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