Developing in the Hirlam GitHub organization
Introduction
Since 2018 and CY43 HIRLAM have used git for code revision control and gitolite as the git server on hirlam.org. HIRLAM is now moving to using Github for ''software development and version control''. This page provides information on how to access the GitHub Hirlam organisation and how to commit your developments, specifically Harmonie. As was the case with hirlam.org's gitolite a fork-and-branch workflow will be used to manage developments.
From CY49, the Harmonie repository has been split into the HarmonieCSC scripting system, this repository, and the common IAL source code repository that contains the code that was previously in Harmonie/src. This document will describe how to obtain and contribute to IAL, while this document explains how to compile and run the code as a submodule in the HarmonieCSC scripting system.
Becoming a member of Hirlam
- Create a GitHub account: https://github.com – click on Sign up. Details here
- Go to settings and add your full name, company and location to make it easier to identify you
- Add your public ssh key(s) to the account. Details here
- Contact your friendly System-core to be invited to the GitHub Hirlam organisation
Fork and branch
This document will discuss forks extensively since this is a very convenient and more or less standard way to work for larger git projects. In short, a fork is a copy of a repository that is linked to the original repository. This makes it possible for developers to work on their own fork and experiment and screw up as much as they want without affecting anyone else. At the same time, getting hold of the latest developments and integrating them into your work is relatively straightforward (at least as long as the conflicts with other developments are not too severe). Finally, when your development is ready, there is built-in machinery to contribute it back to the original repo, or indeed, any other fork. An important point for HIRLAM developers is that HIRLAM has its own IAL fork that developers can contribute to. That said, there is nothing stopping you from contributing directly to ACCORD-NWP/IAL.
WP repo=Hirlam/IAL or ACCORD-NWP/IAL
You can create a user fork of IAL by doing the following:
Click on Fork to create a fork of IAL for your user (USER)
Clone your fork:
git clone git@github.com:USER/IAL.git $HOME/git/github/USER/IAL
Github's extensive documentation on forks is available here
Keep your fork synced
In a terminal change directory to the clone of you fork:
cd $HOME/git/github/USER/IALList the current configured remote repositories for your local repository
git remote -v origin git@github.com:USER/IAL.git (fetch) origin git@github.com:USER/IAL.git (push)In this case, it is only the original remote repository, your own fork, which by default is called origin
Add the HIRLAM fork as a remote repository for your local repository.
New remotes can be configured with the
git remote addcommand followed by an arbitrary name and an SSH address.To add the HIRLAM repository, use the command
git remote add hirlam git@github.com:Hirlam/IAL.gitNote that you can add as many remotes as you want. If you want to add ACCORD-NWP, you would write
git remote add accord git@github.com:ACCORD-NWP/IAL.gitYou can also add your own local repositories as remotes.
Verify the new upstream repository you've specified for your fork.
HIRLAM should now be listed together with your own fork when you use the command
git remote -vgit remote -v origin git@github.com:USER/IAL.git (fetch) origin git@github.com:USER/IAL.git (push) hirlam git@github.com:Hirlam/IAL.git (fetch) hirlam git@github.com:Hirlam/IAL.git (push)Fetch information about branches in the HIRLAM repository to your local repository
Before you can checkout any branches from HIRLAM, you have to fetch the information about the branches there using
fetch. This will also test if you typed in the correct address, have access, and that authentication works.git fetch hirlamUpdate the
dev-CY49T2hbranch in your fork.First, check out the branch locally
git checkout dev-CY49T2hPull the latest version from the HIRLAM repository
git pull hirlam dev-CY49T2hPush the latest changes you pulled from HIRLAM to your fork
git push origin dev-CY49T2h
Further information is available here
Contributing developments to dev-CY49T2h
Feature branches
Contributions to the dev-CY49T2h branch (and any other branch) should be developed in a development branch in your own IAL fork. The following details how you can get your development to hirlam.
Create a feature branch
Switch to the
dev-CY49T2hbranch and make sure it's up to date with hirlam using a pullgit checkout dev-CY49T2h git pullCreate a new branch based on
dev-CY49T2hwith thecheckoutcommand with the-boptiongit checkout -b descriptive-branch-namePush your branch to your github repo. With the
--set-upstreamoption your fork will be set as the default upstreamgit push --set-upstream origin descriptive-branch-nameDo some changes to one or more files and save your changes
Check the status of your repo
git statusAny files you have changes should now be listed in red as unstaged (colours depend on system settings)
Stage the file
To create a commit, you have to stage your changes using
git addgit add file_you_changedIf you changed several files, you have to add all of them. You can use the
--alloption to stage all your filesgit add --allHowever, with the
--alloption, you have to be careful that you don't add any changes you don't want to commit for posterity.Use
git statusagain and your changed files will now be listed as staged in greenCommit your changes
Your changes are now ready to be commited
git commitThis will open an editor window where you can type in a commit message. Good commit messages makes keeping track of history much easier, so write a sentence that explains the changes you did. Save and close the editor and your changes are now commit
See commit history
Use the
logcommand to see the commit history of your branchgit logYour commit is now listed on top.
Push your changes to your fork
Since you have configured your branch to push to your fork using
--set-upstream, you can now push your changes to your fork using onlybash git push
Keep up to date with dev-CY49T2h
Pull
dev-CY49T2hupdates into your branchgit checkout descriptive-branch-name git pull hirlam dev-CY49T2hIf there are no conflicts, git will merge the branches and create a new commit on your branch. If there are conflicts, you will have to resolve them manually.
git statuswill show which files have conflicts. Open the file and search for
>>>>>>to find the conflicting code. How to resolve the conflict will vary on a case by case basis.Once you have resolved the conflicts, you can save the files, add them, and commit them as described above.
Push your merged branch to your github repo
git push
Creating a pull request
Once you have committed to your feature branch and want them included in the upstream repo you should do the following:
Push your branch to your fork as described above
When you push your branch information on how to create a pull request will be presented:
remote: Resolving deltas: 100% (x/x), completed with x local objects. remote: remote: Create a pull request for 'descriptive-branch-name' on GitHub by visiting: remote: https://github.com/USER/IAL/pull/new/feature/descriptive_name_for_developments remote:Follow this link to go to your branch
- Click on
Contributein one of the top banners and click onCreate pull request - This will take you to a new page.
- At the top, you can set which fork and branch to contribute to and from
- The default will be to create a PR to
base repository: ACCORD-NWP/IAL - Click on the drop down menu, search for
Hirlam/IALand choose it (currently, there's 133 forks of IAL, so scrolling is impractical) - Next, click the drop down menu of branches available
Hirlam/IALand choose the one you want to contribute to. - This will take you to a new page with the IAL commit message template
- Fill in the information and click
Create pull request
- Click on
Once your pull request has been created
- request a reviewer
- add labels to the development (feature/enhancement/...)
- add comments to help with the review process (Testbed members used/Changes expected if any/...)
Once the pull request has been approved by the System-core team it will be merged in to the
dev-CY49T2hbranch
Further information is available here
tip
If you put the following in your `.bashrc` it will show the name of the branch in your prompt (when inside a git repository)
```bash
function parse_git_branch () {
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ (\1)/'
}
RED="\[\033[0;31m\]"
YELLOW="\[\033[0;33m\]"
GREEN="\[\033[0;32m\]"
NO_COLOR="\[\033[0m\]"
PS1="$GREEN\u@\h$NO_COLOR:\w$YELLOW\$(parse_git_branch)$NO_COLOR\$ "Useful git/github links
learn git branching is an excellent interactive tool to understand git.
Coding Standards
See Coding standards for Arpège, IFS and Aladin and Arpege/IFS Fortran coding standard (requires ECMWF account)