Note:

If you want to create a new page for developers, you should create it on the Moodle Developer Resource site.

Git for developers: Difference between revisions

From MoodleDocs
Line 20: Line 20:
2. You will create a update script in order to update your github and local repository from git.moodle.org. Add a reference to this Moodle.org Git repository and make your local master branch tracking it:
2. You will create a update script in order to update your github and local repository from git.moodle.org. Add a reference to this Moodle.org Git repository and make your local master branch tracking it:
<code bash>
<code bash>
cd ./YOUR_LOCAL_MOODLE_FOLDER/
git remote add upstream git://git.moodle.org/moodle.git
git remote add upstream git://git.moodle.org/moodle.git
git fetch upstream
git fetch upstream

Revision as of 06:36, 16 December 2010

This document has for purpose to make you start quickly (in the hour) Moodle development with GIT. It doesn't have for purpose to explain you GIT. Please have a look to the full documentation for a better understanding of GIT... (TODO: link to the Git Moodle doc)

The set up

1. Go to Github and create an account.

2. Go to the official Moodle Github repository and click on the Fork button. You now have your own github Moodle repository.

3. Install GIT on your computer. If you are on Mac, git-osx-installer installs it in few click.

4. Now the technical part, you will need to setup your SSH public key, so you can push to your github Moodle repository from your local Moodle repository. On Mac you can go on this Github help page. If you are on another system, go to your Github administration page, to the section SSH Public Keys, and you should see a link to a help page. Is it done? Good, it was the most difficult.

Working on 2.0

1. Create a local clone repository of your github repository. In a terminal: git clone git@github.com:YOUR_GITHUB_USERNAME/moodle.git ./YOUR_LOCAL_MOODLE_FOLDER/

2. You will create a update script in order to update your github and local repository from git.moodle.org. Add a reference to this Moodle.org Git repository and make your local master branch tracking it: cd ./YOUR_LOCAL_MOODLE_FOLDER/ git remote add upstream git://git.moodle.org/moodle.git git fetch upstream git branch --set-upstream master upstream/master

3. Create the update script (name it "update_github")

cd YOUR_LOCAL_MOODLE_FOLDER git checkout master git pull git push origin refs/remotes/upstream/master:master

4. Run the./update_github script. Your local repository ("master" branch) and your github repository ("master" branch) will be updated from git.moodle.org.

5. Now you can work on a new issue. You can use a Git UI tool like SmartGit for these steps:

  • run the update script (the script will switch to "master" branch, so take care to stash/commit the changes of your current branch)
  • create a new branch and switch to it. You should never work in your local master branch.
  • fix your issue with your favorite IDE.
  • commit, push and do a pull request.

Working on 1.9 or earlier branches

This is just a tiny little bit more complicated that working on 2.0. Even though you could work in the same folder that 2.0, create another folder for working in 1.9. It will make things less messy and easier to understand.

1. In a terminal

git clone git@github.com:YOUR_GITHUB_USERNAME/moodle.git ./YOUR_LOCAL_MOODLE_19_FOLDER/

2. Add the remote upstream. You want to update your local MOODLE_19_STABLE branch and your github (called "origin") MOODLE_19_STABLE branch from the official Moodle upstream. git remote add upstream git://git.moodle.org/moodle.git git fetch upstream

3. Now you are going to create a local 1.9 branch. You will keep this branch updated (the branch will track upstream) and you are never going to work in it. git checkout -b MOODLE_19_STABLE upstream/MOODLE_19_STABLE

4. Create the update script in ./update_github cd YOUR_LOCAL_MOODLE_19_FOLDER git checkout MOODLE_19_STABLE git pull git push origin refs/remotes/upstream/MOODLE_19_STABLE:MOODLE_19_STABLE

5. Run the script. Your github MOODLE_19_STABLE branch and your local MOODLE_19_STABLE branch are now updated.

6. You can now work on an issue. You can use a Git UI tool like SmartGit for these steps:

  • run the update script (don't forget to stash/commit the change of your current local branch, you are going to switch to MOODLE_19_STABLE local branch)
  • create a new branch for your issue and switch to it
  • fix your issue with your favorite IDE
  • commit, push and do a pull request

Troubleshooting

  • you want to delete a remote branch on github:

git push origin :CONFLICTING_REMOTE_BRANCH_NAME

  • PHPStorm (beta version) named your 'origin' => 'master' when you cloned your github repository. It is better to rename it as 'origin'.

git remote rename master origin

  • You've been working with Git in the early stages when Moodle HQ were experimenting it. They now changed 'cvshead' to 'master' into upstream (moodle.org Git). You need to rename all your 'cvshead' github and local branches as 'master'. There what you should do (this is not a script to run, execute the command one at the time following the instructions):

  1. go to your root git folder

git fetch origin git fetch upstream git remote prune upstream git remote prune origin

/// FIRST TIME YOU RUN THIS SCRIPT git checkout -b master upstream/master git push origin master

  1. on github, in your repository administration, change the default to 'master'

git push origin :cvshead git branch -d cvshead /// END OF FIRST TIME

git remote set-head origin -a git remote set-head upstream -a

/// OTHER TIME - FOR YOUR OTHER GIT MOODLE FOLDERS git checkout -b master upstream/master git branch -d cvshead /// END OF OTHER TIME

  1. check .git/config that there is no references to 'cvshead', if there are replace with 'master'
  1. optional:
  2. update your update script ('cvshead' => 'master')