GIT help needed

Re: GIT help needed

by Matteo Scaramuccia -
Number of replies: 5
Picture of Core developers Picture of Peer reviewers Picture of Plugin developers

Hi Pierre,
find below my way of working (to be tested in the next days) with Moodle and Git:

  1. Carefully read about Git, having started with "Version Control with Git" (978-0-596-52012-0) and Pro Git;
  2. Git requires attention to define a workflow to work with: Moodle get into SCRUM, some proposals, not to mention other git experiences;
  3. Prepare the environment:
    • GitHub account to share your local work when it will be ready;
    • Windows w/ msysgit and TortoiseGit (+TortoiseSVN TortoisePlink + PuTTYgen + Pageant);
    • Linux w/ git and SSH Keys/ssh-agent;
    • Fork Moodle repo;
  4. Fork Moodle on GitHb;
  5. Create at least two Moodle separate environments, 2.0 and 1.9 respectively;
  6. Configure the previous point by mapping two git repos as in the table below. I guess that there's no need to keep my GitHub fork main branches up to date with the parent ones: remotes should be my friend and they should help to save disk space since I'm using a free account;
  7. Work exclusively with branches. Lurking at different GitHub Moodle-forks repos it seems the naming convention is: [wip_][<Tracker ref>_][m<Moodle branch version if needed, e.g.: 19, 20>_]<branch goal short description>. wip_ will be used when in work in progress i.e.:
    • you've just started working and you've been in the need to share your partial work;
    • you're not sure about your proposal: it works but... share the doubts into the Tracker;
  8. Be prepared to solve issues about merge failures, rebasing, ...

My Moodle Git repos first setup and following work packages:

Task Moodle 2.0 Moodle 1.9
Clone Moodle Git repo from GitHub fork
git clone git@github.com:<username>/moodle.git moodle-20
cd moodle-20
git config --global user.name "Your Name"
git config --global user.email yourmail@domain.tld
git clone git@github.com:<username>/moodle.git moodle-19
cd moodle-19
git config --global user.name "Your Name"
git config --global user.email yourmail@domain.tld
Track Moodle main repo git remote add moodle git://git.moodle.org/moodle.git
git fetch moodle
git branch --track master-moodle moodle/master
git remote add -t MOODLE_19_STABLE -m MOODLE_19_STABLE moodle git://git.moodle.org/moodle.git
git fetch moodle
git branch --track MOODLE_19_STABLE-moodle moodle/MOODLE_19_STABLE
Track Moodle integration repo git remote add integration git://git.moodle.org/integration.git
git fetch integration
git branch --track master-integration integration/master
git remote add -t MOODLE_19_STABLE -m MOODLE_19_STABLE integration git://git.moodle.org/integration.git
git fetch integration
git branch --track MOODLE_19_STABLE-integration moodle/MOODLE_19_STABLE
Show branches git branch
Update remotes (ALL)
git remote update
Look at what has been cooked in the kitchen git diff master-moodle...master-integration git diff MOODLE_19_STABLE-moodle...MOODLE_19_STABLE-integration
Checkout current stable master git checkout master-moodle git checkout MOODLE_19_STABLE-moodle
Create a WIP branch git branch wip_[<Tracker ref>_][m20_]<branch goal short description>
git checkout wip_[<Tracker ref>_][m20_]<branch goal short description>
git branch wip_[<Tracker ref>_][m19_]<branch goal short description>
git checkout wip_[<Tracker ref>_][m19_]<branch goal short description>
Start working

git status
git add <./file/folder>
git status
git commit -m "<reasons for this commit>"

Optionally update (ff) your WIP branch on the next run
git checkout wip_[<Tracker ref>_][m20_]<branch goal short description>
git merge moodle/master-moodle
git checkout wip_[<Tracker ref>_][m19_]<branch goal short description>
git merge moodle/MOODLE_19_STABLE-moodle
Optionally rename your WIP branch
git branch -m wip_[<Tracker ref>_][m20_]<branch goal short description> [<Tracker ref>_][m20_]<branch goal short description> git branch -m wip_[<Tracker ref>_][m19_]<branch goal short description> [<Tracker ref>_][m19_]<branch goal short description>
Publish/Update the branch and give refs into the Tracker + Test Cases
git push origin [<Tracker ref>_][m20_]<branch goal short description> git push origin [<Tracker ref>_][m19_]<branch goal short description>
Optionally track your remote branch (required if you're the only one able to push on it?)
git config branch.[<Tracker ref>_][m20_]<branch goal short description>.remote origin
git config branch.[<Tracker ref>_][m20_]<branch goal short description>.merge refs/heads/[<Tracker ref>_][m20_]<branch goal short description>
git config branch.[<Tracker ref>_][m19_]<branch goal short description>.remote origin
git config branch.[<Tracker ref>_][m19_]<branch goal short description>.merge refs/heads/[<Tracker ref>_][m19_]<branch goal short description>

Feedbacks are welcome! I'm at the very beginning...

HTH,
Matteo

Average of ratings: Useful (1)
In reply to Matteo Scaramuccia

Re: GIT help needed

by Pierre Pichet -

Matteo

Thanks a lot for all the details.

What I understand from Git doc is that when working on a project, they suggest to do commits in the WIB branch at different parts of the project so that things will be clearer for the others when everything will be pushed.

As usual in a larger project we create sub-tasks.

 

Pierre

P.S. It is a pitty that there are no more scrollling, printing you large table or copy and paste is the only way to give its full value smile.

In reply to Matteo Scaramuccia

Re: GIT help needed

by Joseph Rézeau -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers Picture of Translators

Hi Matteo,

This looks like the kind of "GIT for Moodle scenario" I have been asking for in this thread.

Could you please put it somewhere in the Moodle Wiki Documentation for easy reference and so that moodlers can add to it?

It would help a lot if you would number the various steps.

ATB

Joseph

In reply to Matteo Scaramuccia

Re: GIT help needed

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

That is a good start to what is asked for. Thanks. You even used the same remote names as me (origin and moodle).

Only a few things I would disagree with.

1. In "Track Moodle main repo" I think calling your local copy of master something different is a bad idea.

2. When doing "Create a WIP branch", you can do it with one line:

git checkout -b <newbranchname> moodle/master

That switches you to a new branch with the given name, starting from where moodle/master is.

3. Don't merge from master into your WIP brach. Eventually, once you work is included in Moodle core, that will leave a nasty mess (and so the integrators will probably reject your branch).

Instead, you should rebase your branch onto the latest moodle/master, so that when it is integrated, the history is as clean as possible.

4. I don't think it is ever required to "Optionally track your remote branch".

 

3. is the only serious comment.

In reply to Tim Hunt

Re: GIT help needed

by Matteo Scaramuccia -
Picture of Core developers Picture of Peer reviewers Picture of Plugin developers

Hi Tim,
thanks for your comments! I shared something should map my preferred way of working before testing it in the real world, just to understand if I was in the right direction, especially being a newbie and not able to find some answers that are part of my workflow, see http://moodle.org/mod/forum/discuss.php?d=168094#p740189.

On evaluating your comments I've just realized that checking out a remote tracking branch doesn't update my "local working copy" as expected (see below in Windows, my origin was created @ 4 Feb!): I'll reconsider Martin's hint, http://docs.moodle.org/en/Development:Quick_GIT_starting_guide_for_Moodle_development... I've probably detached both HEAD and the thing over my neck blush.

matteo@MATTEO-NB /C/Projects/Moodle/www/git/moodle-20 (master-moodle)
$ git remote update
Fetching origin
Fetching moodle
Fetching integration

matteo@MATTEO-NB /C/Projects/Moodle/www/git/moodle-20 (master-moodle)
$ git branch -a
master
master-integration
* master-moodle
remotes/integration/MOODLE_16_STABLE
remotes/integration/MOODLE_17_STABLE
remotes/integration/MOODLE_18_STABLE
remotes/integration/MOODLE_19_STABLE
remotes/integration/master
remotes/moodle/MOODLE_16_STABLE
remotes/moodle/MOODLE_17_STABLE
remotes/moodle/MOODLE_18_STABLE
remotes/moodle/MOODLE_19_STABLE
remotes/moodle/master
remotes/origin/HEAD -> origin/master
remotes/origin/MOODLE_16_STABLE
remotes/origin/MOODLE_17_STABLE
remotes/origin/MOODLE_18_STABLE
remotes/origin/MOODLE_19_STABLE
remotes/origin/master

matteo@MATTEO-NB /C/Projects/Moodle/www/git/moodle-20 (master-moodle)
$ git diff master...master-moodle

matteo@MATTEO-NB /C/Projects/Moodle/www/git/moodle-20 (master-moodle)
$

TIA,
Matteo

In reply to Matteo Scaramuccia

Re: GIT help needed

by Matteo Scaramuccia -
Picture of Core developers Picture of Peer reviewers Picture of Plugin developers

Mmmhhh... it looks like I've missed git pull [moodle] to let my worflow run as I expected for 2.0 branch. I guess I'll have more issues during the long way to my first commits into github...

Matteo