{ "cells": [ { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "fragment" } }, "source": [ "# Development with Git\n", "\n", " Here we provide a detailed instruction to the use of Git and GitHub and their workflows, which are essential to the code development of CLIMADA. \n", "\n" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "slide" } }, "source": [ "## Git and GitHub\n", "\n", "- Git's not that scary\n", " - 95% of your work on Git will be done with the same handful of commands (the other 5% will always be done with careful Googling)\n", " - Almost everything in Git can be undone by design (but use `rebase`, `--force` and `--hard` with care!)\n", " - Your favourite IDE (Spyder, PyCharm, ...) will have a GUI for working with Git, or you can download a standalone one.\n", "- The [Git Book](https://git-scm.com/book/en/v2) is a great introduction to how Git works and to using it on the command line.\n", "- Consider using a GUI program such as “git desktop” or “Gitkraken” to have a visual git interface, in particular at the beginning. Your python IDE is also likely to have a visual git interface. \n", "- Feel free to ask for help" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "subslide" } }, "source": [ "![](img/git_gui.png)" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "slide" } }, "source": [ "### What we assume you know\n", "\n", "We're assuming you're all familiar with the basics of Git.\n", "\n", "- What (and why) is version control\n", "- How to clone a repository\n", "- How to make a commit and push it to GitHub\n", "- What a branch is, and how to make one\n", "- How to merge two branches\n", "- The basics of the GitHub website\n", "\n", "If you're not feeling great about this, we recommend\n", "- sending me a message so we can arrange an introduction with CLIMADA\n", "- exploring the [Git Book](https://git-scm.com/book/en/v2)" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "slide" } }, "source": [ "### Terms we'll be using today\n", "\n", "These are terms that will come up a lot, so let's make sure we know them\n", "\n", "- local versus remote\n", " - Our **remote** repository is hosted on GitHub. This is the central location where all updates to CLIMADA that we want to share end up. If you're updating CLIMADA for the community, your code will end up here too.\n", " - Your **local** repository is the copy you have on the machine you're working on, and where you do your work.\n", " - Git calls the (first, default) remote the `origin`\n", " - (It's possible to set more than one remote repository, e.g. you might set one up on a network-restricted computing cluster)" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "subslide" } }, "source": [ "- push, pull and pull request\n", " - You **push** your work when you send it from your local machine to the remote repository\n", " - You **pull** from the remote repository to update the code on your local machine\n", " - A **pull request** is a standardised review process on GitHub. Usually it ends with one branch merging into another" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "subslide" } }, "source": [ "- Conflict resolution\n", " - Sometimes two people have made changes to the same bit of code. Usually this comes up when you're trying to merge branches. The changes have to be manually compared and the code edited to make sure the 'correct' version of the code is kept. " ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "slide" } }, "source": [ "## Gitflow " ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "slide" } }, "source": [ "Gitflow is a particular way of using git to organise projects that have\n", "- multiple developers\n", "- working on different features\n", "- with a release cycle\n", "\n", "It means that\n", "- there's always a stable version of the code available to the public\n", "- the chances of two developers' code conflicting are reduced\n", "- the process of adding and reviewing features and fixes is more standardised for everyone\n", "\n", "Gitflow is a _convention_, so you don't need any additional software.\n", "- ... but if you want you can get some: a popular extension to the git command line tool allows you to issue more intuitive commands for a Gitflow workflow.\n", "- Mac/Linux users can install git-flow from their package manager, and it's included with Git for Windows " ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "slide" } }, "source": [ "### Gitflow works on the `develop` branch instead of `main`" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "slide" } }, "source": [ "![](img/flow_1.png)\n", "\n", "- The critical difference between Gitflow and 'standard' git is that almost all of your work takes place on the `develop` branch, instead of the `main` (formerly `master`) branch.\n", "- The `main` branch is reserved for planned, stable product releases, and it's what the general public download when they install CLIMADA. The developers almost never interact with it." ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "slide" } }, "source": [ "### Gitflow is a feature-based workflow" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "![](img/flow_2.png)\n", "\n", "- This is common to many workflows: when you want to add something new to the model you start a new branch, work on it locally, and then merge it back into `develop` **with a pull request** (which we'll cover later)." ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "subslide" } }, "source": [ "- By convention we name all CLIMADA feature branches `feature/*` (e.g. `feature/meteorite`).\n", "- Features can be anything, from entire hazard modules to a smarter way to do one line of a calculation. Most of the work you'll do on CLIMADA will be a features of one size or another.\n", "- We'll talk more about developing CLIMADA features later!" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "slide" } }, "source": [ "### Gitflow enables a regular release cycle" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "![](img/flow_3.png)\n", "\n", "- A release is usually more complex than merging `develop` into `main`." ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "subslide" } }, "source": [ "- So for this a `release-*` branch is created from `develop`. We'll all be notified repeatedly when the deadline is to submit (and then to review) pull requests so that you can be included in a release.\n", "- The core developer team (mostly Emanuel) will then make sure tests, bugfixes, documentation and compatibility requirements are met, merging any fixes back into `develop`.\n", "- On release day, the release branch is merged into `main`, the commit is tagged as a release and the release notes are published on the GitHub at " ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "slide" } }, "source": [ "### Everything else is hotfixes" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "![](img/flow_4.png)\n", "\n", "- The other type of branch you'll create is a hotfix." ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "subslide" } }, "source": [ "- Hotfixes are generally small changes to code that do one thing, fixing typos, small bugs, or updating docstrings. They're done in much the same way as features, and are usually merged with a pull request.\n", "- The difference between features and hotfixes is fuzzy and you don't need to worry about getting it right.\n", "- Hotfixes will occasionally be used to fix bugs on the `main` branch, in which case they will merge into both `main` and `develop`.\n", "- Some hotfixes are so simple - e.g. fixing a typo or a docstring - that they don't need a pull request. Use your judgement, but as a rule, if you change what the code does, or how, you should be merging with a pull request." ] } ], "metadata": { "celltoolbar": "Slideshow", "kernelspec": { "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.10.13" }, "vscode": { "interpreter": { "hash": "fe76ddefd4ac3b756bca82b2809865e7c67c346a46477cb9eec4ead581742ab6" } } }, "nbformat": 4, "nbformat_minor": 4 }