Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

πŸ–₯️ Lecture slides β€” Session 02 (Fri Oct 2)

Version ControlΒΆ

Version control is a system that organizes and tracks the versions of code.

Versions of a research paper. File naming and tracked changes can become messy. From PhD Comics.

Versions of a research paper. File naming and tracked changes can become messy. From PhD Comics.

It keeps track of the changes and who made them. See further discussion on The Turing Way Community, 2022. Here are the main points.

An illustration of a main branch

FigureΒ 2:An illustration of a main branch from The Turing Way [1].

At each commit, git records the changes. Several people can work on the same file; version control recognizes conflicts and provides options to resolve them. Good practice keeps the main branch the cleanest branch. Create additional branches to work on specific parts of the project.

An illustration of a sub branch that gets created, committed, and merged.

FigureΒ 3:An illustration of multiple sub branches that get created, committed, and merged to the main branch. From The Turing Way [1].

What is the difference between git and GitHub?

Set up GitΒΆ

Set your user name and e-mail:

git config --global user.name "superseismo"
git config --global user.email "superseismo@uw.edu"

Use the same user name as your GitHub account, so GitHub attributes your commits to you. You only need to do this once per computer.

GitHubΒΆ

Create a GitHub accountΒΆ

Create a GitHub account using the same user name and email address as in your git config. Free accounts include unlimited public and private repositories; paid plans add organization and enterprise features you will not need in this course.

AuthenticationΒΆ

GitHub requires two-factor authentication (2FA) for all contributors β€” set it up when you create the account, with an authenticator app, a passkey, or the GitHub Mobile app. Your account password alone never authenticates git operations; use one of the following:

More details on GitHub authentication here. The git cheat sheet is a handy command reference.

Get a copy of an existing repositoryΒΆ

There are two ways to work from an existing repository, and they are not the same:

Rule of thumb: clone repositories you own or have write access to (your MLGEO2026_UWNETID repository, your team’s project); fork, then clone your fork for repositories you do not have write access to (this book, most open source projects).

Create a new repositoryΒΆ

You are going to create your first repository. Do it once, with one of the following three methods.

From the browser:

  1. Log in to GitHub. In the upper-right corner of any page, click +, then New repository.
  2. Name it, choose public or private.
  3. Check Add a README file and choose a license.
  4. Click Create repository.
  5. Clone it to your computer: git clone https://github.com/superseismo/my-repo.git

From the gh CLI (one command does all of the above):

gh repo create my-repo --public --add-readme --license mit --clone

From git alone, when the code already exists in a local directory: create an empty repository on GitHub first (browser method, steps 1–4, without the README), then

cd my-project
git init
git add .
git commit -m "first commit"
git remote add origin https://github.com/superseismo/my-project.git
git push -u origin main

Choose a local path outside cloud-synced folders (Dropbox, Google Drive) to reduce headaches, then open the repository in VS Code or your preferred editor. What belongs in a repository β€” README, license, CONTRIBUTING file, environment specification β€” is covered in 1.1 Open Reproducible Science; best practices follow Nenadic et al. (2022). Add a .gitignore file early to keep large data files and generated outputs from ever being committed.

The everyday cycleΒΆ

Day to day, contributing to a repository is a loop of four commands:

  1. Update your local copy before you start:

    git pull
  2. Edit files in your editor, then check what changed:

    git status
    git diff
  3. Stage and commit the changes with a descriptive message:

    git add <file1> <file2>       # or: git add .  for all modified files
    git commit -m "Your descriptive commit message"

    GitHub uses staging as the terminology for collecting the changes that the next commit will record on the remote server.

  4. Push the commits to GitHub:

    git push

Example workflowΒΆ

A complete pass through the loop, ending in a pull request:

  1. Update and branch. Start from the current main branch and create a working branch:

    git pull
    git switch -c fix-readme
  2. Edit. Open example.txt, make your changes, and review them with git diff.

  3. Stage and commit:

    git add example.txt
    git commit -m "Clarify installation instructions"
  4. Push the branch to GitHub:

    git push -u origin fix-readme
  5. Open a pull request. Either click the link git prints after the push, use the Compare & pull request button on the repository page, or run:

    gh pr create

    Once the pull request is reviewed and merged, switch back to main and pull the merged result: git switch main, then git pull.

Undo changesΒΆ

Modern git separates β€œundo” into explicit commands. Two safe, everyday ones:

To throw away your local edits to a file and return to the last committed version:

git restore mycode.py

You may see git checkout and git reset HEAD <file> in older tutorials; git restore (for files) and git switch (for branches) replaced them in 2019 because checkout did both jobs at once and made mistakes easy.

Work as a teamΒΆ

The main branch should remain the clean, official version for the public.

Pull requests using GitHub: Found in EarthDataScience. Source: Earth Lab, Alana Faller

Pull requests using GitHub: Found in EarthDataScience. Source: Earth Lab, Alana Faller

GitHub Issues: Use template

GitHub Issues: Use template

Further discussion here.

Repository StructureΒΆ

your-repo/ 
β”œβ”€β”€ .github/ # GitHub-specific files (e.g., issue templates, workflows) 
β”‚ β”œβ”€β”€ ISSUE_TEMPLATE/ # for sophisticated community package
β”‚ β”œβ”€β”€ PULL_REQUEST_TEMPLATE.md  # for sophisticated community package
β”‚ └── workflows/ 
β”‚ └── ci.yml # Continuous Integration configuration, publish package, build container, test, build github-pages
β”œβ”€β”€ docs/ # Documentation files 
β”‚ β”œβ”€β”€ conf.py # Sphinx configuration file 
β”‚ β”œβ”€β”€ index.rst # Main documentation file 
β”‚ └── ... 
β”œβ”€β”€ your_package/ # Main package directory 
β”‚ β”œβ”€β”€ init.py # Package initialization
β”‚ β”œβ”€β”€ module1.py # Example module 
β”‚ β”œβ”€β”€ module2.py # Example module 
β”‚ └── ... 
β”œβ”€β”€ tests/ # Unit tests 
β”‚ β”œβ”€β”€ init.py 
β”‚ β”œβ”€β”€ test_module1.py # Tests for module1 
β”‚ β”œβ”€β”€ test_module2.py # Tests for module2 
β”‚ └── ... 
β”œβ”€β”€ .gitignore # Git ignore file 
β”œβ”€β”€ environment.yml # Conda environment file 
β”œβ”€β”€ requirements.txt # Pip requirements file 
β”œβ”€β”€ pyproject.toml # project TOML file for packaging 
β”œβ”€β”€ README.md # Project README file 
β”œβ”€β”€ LICENSE # License file 
└── CONTRIBUTING.md # Contribution guidelines

Explanation of Key Files and DirectoriesΒΆ

Example pyproject.tomlΒΆ

This is a newer standard introduced by PEP 518 and PEP 621. It aims to provide a unified way to specify build system requirements and package metadata. It is part of the effort to modernize Python packaging. Here’s an example pyproject.toml file for packaging your project:

[build-system]
requires = ["setuptools>=42", "wheel"]
build-backend = "setuptools.build_meta"

[project]
name = "your_package"
version = "0.1.0"
description = "A brief description of your project"
readme = "README.md"
requires-python = ">=3.11"
license = {text = "MIT"}
authors = [
    {name = "Your Name", email = "your.email@example.com"}
]
dependencies = [
    "numpy",
    "pandas",
]

[project.urls]
Homepage = "https://github.com/yourusername/your-repo"

[tool.setuptools]
packages = ["your_package"]

[project.scripts]
your_command = "your_package.module:function"

This structure keeps a Python project organized and predictable for collaborators. GitHub itself does not directly use the pyproject.toml file. Instead, you can set up GitHub Actions to automate tasks such as testing, building, and publishing your package.

AI-generated commits and code reviewΒΆ

By 2026, much of the code that lands in a student repository was first drafted by an AI assistant, sometimes as a whole commit or pull request opened by the agent itself. Version control is where you stay in charge of that. Three rules for this course:

Publish your softwareΒΆ

If the software will be used for future research and would be cited by the community, publish it on Zenodo to get a DOI. See 1.1 Open Reproducible Science for the workflow, licensing, and citation practices.

Exercise β€” dry run: your first pull requestΒΆ

Pull requests carry real weight in this course: the class leaderboard in 3.5 Multiclass Classification scores prediction files that you submit by PR. This exercise is ungraded, so your first real PR is not your first scored one. It runs entirely against your own MLGEO2026_UWNETID repository (created in 1.9), where a mistake costs nothing.

  1. Clone your repository (if you have not already) and create a branch:

    git clone https://github.com/superseismo/MLGEO2026_UWNETID.git
    cd MLGEO2026_UWNETID
    git switch -c hello-world
  2. Add a line to README.md β€” for example, one sentence about what you want out of this course. Check the change with git diff.

  3. Commit and push the branch:

    git add README.md
    git commit -m "Add hello-world line to README"
    git push -u origin hello-world
  4. Open the pull request on GitHub (or gh pr create). Write one sentence in the description saying what the change is.

  5. Review your own diff in the Files changed tab β€” the same view a reviewer of your leaderboard submission will see. Then merge the PR.

  6. Back on your computer, sync main and delete the merged branch:

    git switch main
    git pull
    git branch -d hello-world

Success looks like: your README edit visible on the main branch on GitHub, a merged PR in the repository’s Pull requests tab, and a local main branch that matches the remote.

Additional ResourcesΒΆ

The Turing Way has excellent resources for version control.

FootnotesΒΆ
ReferencesΒΆ
  1. Community, T. T. W. (2022). The Turing Way: A handbook for reproducible, ethical and collaborative research. 10.5281/zenodo.6909298
  2. Nenadic, A., Crouch, S., Graham, J., Mangham, S., Laird, J., & Robinson, M. (2022). carpentries-incubator/python-intermediate-development: beta (beta). 10.5281/zenodo.6532057