No description
Find a file
2025-08-18 22:57:15 +02:00
workflows_sketches_presentation animate first workflow too 2025-08-18 22:56:08 +02:00
auth.py add solution and minimal solution 2025-08-18 22:57:15 +02:00
cheatsheet.md first commit 2025-08-13 16:29:30 +02:00
exercise.md first commit 2025-08-13 16:29:30 +02:00
git-commands-visualizations.pdf first commit 2025-08-13 16:29:30 +02:00
minimal_auth.py add solution and minimal solution 2025-08-18 22:57:15 +02:00
README.md full lecture notes 2025-08-18 22:57:15 +02:00
workflow_sketches.pdf first commit 2025-08-13 16:29:30 +02:00

git

Setup

  • Login with your username found on your name badge and set the initial password for your account: https://git.aspp.school/user/login
  • You'll have to type that password many many times this week: choose wisely!
  • We will use the exercise in the repo for the rest of the lecture
  • find a partner to do pair-programming for this lecture by finding someone with the same tarot card as you
  • before starting, make yourself acquainted with the meanining and the power of the tarot cards: carefully read this booklet

A cautionary quote

My first instinct is to sell all my computers, fake my own death, move to another planet, and reinvent computing from scratch, rather than try to understand Git.

I rarely actually do that, mind you. But the urge is there.

— Lars Wirzenius (Linux kernel developer)

Warm-Up

  • how to start a repo from scratch?
    • git init local method
    • on an online forge (GitHub, GitLab, …): git clone
  • how to revert mistakes?
    • before commit:
      • git restore <file> [discard changes in the working directory] changes files
      • git restore --staged <file> [unstage changes ➔ opposite of git add <file>, does not modify the working directory]
    • after commit:
      • git revert <commit> [creates a new commit, modifies the working directory]
      • git reset <commit> [only reset the HEAD pointer, does not modify the working directory] rewrites history ➔ can not be used if you have already pushed to some remote
      • git reset --hard <commit> [reset HEAD and modify working directory] rewrites history and changes files ➔ can not be used if you have already pushed to some remote
  • how to move the whole working directory to a specific point in history?
    • git checkout <commit>DETACHED HEAD problem, changes files
    • interaction with branches: git branch <branch_name> + git switch <branch_name>
  • how to copy a file from a different branch:
    • git checkout <branch> <file> ➔ the file is staged automatically
    • git restore --source=<branch> <file ➔ the file is not staged
  • git gui: building commits along the way interactively (for the mess around type of workflows)
  • check out these sketches for a graphical visualization of git commands!

Workflows

Look at the sketches

  1. lone scientist local ➔ working alone in the cellar without Internet (local git)
  2. lone scientist remote ➔ uploading their software to the Internet in the hope it can be useful for other people (local git + one personal repo on a git-forge)
  3. research group ➔ sharing one software project with some other befriended scientist working in a different place (local git + group repo on a git-forge + permissions)
  4. fully distributed software development ➔ using the most typical open source software workflows as used by numpy, scipy, sklearn, etc. (like above + we don't trust our contributors, i.e. work strictly with forks)

The Open Source workflow

  • remotes: git pull <from_where> <what>, git push <where> <what>, git fetch <from_where> <what>, git merge <another_branch>
  • git-forge: forks, branches and PRs: notice the difference between fork and clone!!!
  • strategies for keeping your fork up-to-date: your main, origin's and upstream's main, short-lived and long-lived topic branches
  • a more thorough and detailed explanation can be found on the SciPy Contributor's Guide. This guide can be adapted to your own needs, see gitwash.
  • GitHub and GitLab are just options (git≠GitHub): there are many git-forges out there, both installable on premises (e.g. forgejo) ) or as an online service for free and open source software (e.g. codeberg