{"id":695,"date":"2012-06-29T17:29:58","date_gmt":"2012-06-29T16:29:58","guid":{"rendered":"http:\/\/www.nathankowald.com\/blog\/?p=695"},"modified":"2016-11-13T17:04:54","modified_gmt":"2016-11-13T17:04:54","slug":"using-git-with-moodle","status":"publish","type":"post","link":"https:\/\/www.nathankowald.com\/blog\/2012\/06\/using-git-with-moodle\/","title":{"rendered":"Using Git with Moodle"},"content":{"rendered":"<div style=\"padding: 7px; background-color: #f3fceb; border: 2px solid #92DE7E; margin-top: 15px;\"><strong>New to Git?<\/strong> Learn it in 15 minutes <a title=\"Learn Git\" href=\"http:\/\/try.github.com\" target=\"_blank\">here<\/a>.<\/div>\n<p><\/p>\n<p>Working on Moodle with Git is a breeze!<br \/>\nPreviously, applying security updates to our Moodle 1.9 site was a ballbreak because we&#8217;d changed so much core code. I&#8217;d have to go through and apply fixes individually to each updated file to make sure new changes didn&#8217;t clash with our custom changes.<\/p>\n<p>We now maintain a <em>forked<\/em> copy of <a href=\"https:\/\/github.com\/moodle\/moodle\">Moodle<\/a> on our college&#8217;s GitHub account.<br \/>\nMaintaining a copy of Moodle in our own GitHub repository allows us to easily update, manage changes (add our theme, blocks, modules) and <a href=\"http:\/\/docs.moodle.org\/dev\/Git_for_developers#Preparing_a_patch\">contribute bug fixes<\/a>.<\/p>\n<p>It took me a while to realise that with Git, we can maintain our own version (branch) of Moodle, based on the latest STABLE release. We can keep our added blocks, modules and custom theme separate from STABLE branches. We&#8217;re only\u00a0<em>adding<\/em>\u00a0files to our branch and not changing core files, so getting and merging with latest stable updates is easy.<\/p>\n<p>These pages do a great job of explaining Moodle development with Git:<\/p>\n<ul>\n<li><a href=\"http:\/\/docs.moodle.org\/22\/en\/Git_for_Administrators\">http:\/\/docs.moodle.org\/22\/en\/Git_for_Administrators<\/a><\/li>\n<li><a href=\"http:\/\/docs.moodle.org\/dev\/Git_for_developers\">http:\/\/docs.moodle.org\/dev\/Git_for_developers<\/a><\/li>\n<li><a href=\"http:\/\/docs.moodle.org\/dev\/Tutorial_on_using_git_in_Moodle_development\">http:\/\/docs.moodle.org\/dev\/Tutorial_on_using_git_in_Moodle_development<\/a><\/li>\n<\/ul>\n<h2>Installing Moodle using Git<\/h2>\n<ol>\n<li><a href=\"https:\/\/github.com\/login\" target=\"_blank\">Sign in<\/a> or <a href=\"https:\/\/github.com\/signup\/free\" target=\"_blank\">create your GitHub account<\/a> &#8211; free for public repositories.\n<li>Download and install Git on your server. <a href=\"https:\/\/help.github.com\/articles\/set-up-git\" target=\"_blank\">Instructions here<\/a>.<br \/>\n<strong>Note:<\/strong> Port 22 (SSH) is blocked and a proxy is used at the College I work at. <a href=\"http:\/\/www.nathankowald.com\/blog\/2012\/03\/github-on-port-443-through-a-proxy\/\">I followed these steps<\/a> to use Git on port 443 through our proxy.<\/li>\n<li>Browse to Moodle&#8217;s GitHub repository &#8211;\u00a0<a href=\"https:\/\/github.com\/moodle\/moodle\">https:\/\/github.com\/moodle\/moodle<\/a><\/li>\n<li>Click &#8216;Fork&#8217; in the top right of the web interface.<\/li>\n<li>Clone your forked repository locally into a folder on your server. Change &#8216;username&#8217; below to your GitHub username.\n<pre class=\"prettyprint lang-sh\">\r\n# Clone our fork into a directory called 'moodle'\r\ngit clone git@github.com:username\/moodle.git moodle<\/pre>\n<\/li>\n<li>Configure remote repositories.<br \/>\nAdd &#8216;upstream&#8217; to track changes to the official moodle repository.<\/p>\n<pre class=\"prettyprint lang-sh\">\r\n# Change the active directory in the prompt to the newly cloned 'moodle' directory\r\ncd moodle\r\n\r\n# Assigns the original repo to a remote called 'upstream'\r\ngit remote add upstream\u00a0git@github.com:moodle\/moodle.git\r\n\r\n# Pulls in changes not present in your local repository, without modifying your files\r\ngit fetch upstream\r\n\r\n#\u00a0Creates a new branch called MOODLE_23_STABLE\r\n# sets it to track the remote branch MOODLE_23_STABLE from the upstream repository\r\ngit branch --track MOODLE_23_STABLE origin\/MOODLE_23_STABLE\r\n\r\n# show all branches\r\ngit branch -a\r\n\r\n# should show:\r\nMOODLE_23_STABLE\r\n* master\r\nremotes\/origin\/HEAD -&gt; origin\/master\r\nremotes\/origin\/MOODLE_13_STABLE\r\nremotes\/origin\/MOODLE_14_STABLE\r\nremotes\/origin\/MOODLE_15_STABLE\r\nremotes\/origin\/MOODLE_16_STABLE\r\nremotes\/origin\/MOODLE_17_STABLE\r\nremotes\/origin\/MOODLE_18_STABLE\r\nremotes\/origin\/MOODLE_19_STABLE\r\nremotes\/origin\/MOODLE_20_STABLE\r\nremotes\/origin\/MOODLE_21_STABLE\r\nremotes\/origin\/MOODLE_22_STABLE\r\nremotes\/origin\/MOODLE_23_STABLE\r\nremotes\/origin\/master\r\nremotes\/upstream\/MOODLE_13_STABLE\r\nremotes\/upstream\/MOODLE_14_STABLE\r\nremotes\/upstream\/MOODLE_15_STABLE\r\nremotes\/upstream\/MOODLE_16_STABLE\r\nremotes\/upstream\/MOODLE_17_STABLE\r\nremotes\/upstream\/MOODLE_18_STABLE\r\nremotes\/upstream\/MOODLE_19_STABLE\r\nremotes\/upstream\/MOODLE_20_STABLE\r\nremotes\/upstream\/MOODLE_21_STABLE\r\nremotes\/upstream\/MOODLE_22_STABLE\r\nremotes\/upstream\/MOODLE_23_STABLE\r\nremotes\/upstream\/master\r\n\r\n# switch to the latest stable branch\r\ngit checkout MOODLE_23_STABLE<\/pre>\n<\/li>\n<\/ol>\n<h2>New branch for your changes<\/h2>\n<p>After you&#8217;ve switched to MOODLE_23_STABLE you can create a new branch to store any changes you want to make to your chosen STABLE version.<\/p>\n<pre class=\"prettyprint lang-sh\">\r\n# creates a branch called conel-MOODLE_23_STABLE, based on 2.3 STABLE\r\ngit checkout -b conel-MOODLE_23_STABLE<\/pre>\n<p>In this example I create a new branch called <strong>conel-<\/strong>MOODLE_23_STABLE that will contain our added\u00a0modules, blocks and custom theme.<\/p>\n<p>After we&#8217;ve added files to our local copy of Moodle we want to push these to our conel-MOODLE_23_STABLE branch.<\/p>\n<pre class=\"prettyprint lang-sh\">\r\n# Adds our changed files\r\ngit add .\r\n\r\ngit commit -m 'add blocks, modules, theme'\r\n\r\n# Push your changes to conel-MOODLE_23_STABLE\r\ngit push origin conel-MOODLE_23_STABLE<\/pre>\n<h2>Updating Moodle<\/h2>\n<p>With Git, I simply fetch the latest updates from the Moodle repository (upstream), push them to my copy of moodle (origin), pull down the latest changes locally to my server, then merge them with conel-MOODLE_23_STABLE.\u00a0Because conel-MOODLE_23_STABLE <em>mostly<\/em> contains new code (avoiding core changes as much as possible) I&#8217;ve yet to experience a merge conflict.<\/p>\n<p><strong>Here&#8217;s the (currently manual) process of getting the latest Moodle changes into our forked copy.<\/strong><\/p>\n<pre class=\"prettyprint lang-sh\">\r\ngit fetch upstream\r\n\r\ngit push origin refs\/remotes\/upstream\/MOODLE_22_STABLE:MOODLE_22_STABLE\r\ngit push origin refs\/remotes\/upstream\/MOODLE_23_STABLE:MOODLE_23_STABLE\r\ngit push origin refs\/remotes\/upstream\/master:master\r\n\r\n# In branch conel-MOODLE_23_STABLE\r\ngit checkout MOODLE_23_STABLE\r\ngit pull\r\ngit checkout conel-MOODLE_23_STABLE\r\ngit merge MOODLE_23_STABLE<\/pre>\n<h2>Notification of Updates<\/h2>\n<p>GitHub provides a handy feed of commits to any branch\/master.<br \/>\nYou can easily subscribe to <a href=\"https:\/\/github.com\/moodle\/moodle\/commits\/MOODLE_23_STABLE\">Moodle commits for any branch you want<\/a>. At work I use\u00a0Outlook 2010 to subscribe to MOODLE_22_STABLE and MOODLE_23_STABLE.<\/p>\n<p>The <a href=\"http:\/\/docs.moodle.org\/22\/en\/Git_for_Administrators\">Git for Administrators<\/a> page says, <em>&#8220;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&#8221;<\/em>.<\/p>\n<p>I find this visual reminder useful.\u00a0I&#8217;ve added this feed to my favourites so it&#8217;s prominent in Outlook.<\/p>\n<p><a href=\"http:\/\/www.nathankowald.com\/blog\/wp-content\/uploads\/2012\/06\/moodle-commits.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-589\" title=\"Moodle Commits Atom Feed\" src=\"http:\/\/www.nathankowald.com\/blog\/wp-content\/uploads\/2012\/06\/moodle-commits.png\" alt=\"\" width=\"612\" height=\"357\" srcset=\"https:\/\/www.nathankowald.com\/blog\/wp-content\/uploads\/2012\/06\/moodle-commits.png 612w, https:\/\/www.nathankowald.com\/blog\/wp-content\/uploads\/2012\/06\/moodle-commits-300x175.png 300w\" sizes=\"auto, (max-width: 612px) 100vw, 612px\" \/><\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>New to Git? Learn it in 15 minutes here. Working on Moodle with Git is a breeze! Previously, applying security updates to our Moodle 1.9 site was a ballbreak because we&#8217;d changed so much core code. I&#8217;d have to go through and apply fixes individually to each updated file to make sure new changes didn&#8217;t [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[13,15,7],"tags":[],"class_list":["post-695","post","type-post","status-publish","format-standard","hentry","category-git","category-moodle","category-web-development"],"acf":[],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.nathankowald.com\/blog\/wp-json\/wp\/v2\/posts\/695","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.nathankowald.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.nathankowald.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.nathankowald.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.nathankowald.com\/blog\/wp-json\/wp\/v2\/comments?post=695"}],"version-history":[{"count":42,"href":"https:\/\/www.nathankowald.com\/blog\/wp-json\/wp\/v2\/posts\/695\/revisions"}],"predecessor-version":[{"id":1771,"href":"https:\/\/www.nathankowald.com\/blog\/wp-json\/wp\/v2\/posts\/695\/revisions\/1771"}],"wp:attachment":[{"href":"https:\/\/www.nathankowald.com\/blog\/wp-json\/wp\/v2\/media?parent=695"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.nathankowald.com\/blog\/wp-json\/wp\/v2\/categories?post=695"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.nathankowald.com\/blog\/wp-json\/wp\/v2\/tags?post=695"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}