Everything from the workshop on one page. Print it, or keep it open in a tab.
Git: set up once ¶ Command What it does git config --global user.name "Your Name"The author name on your commits git config --global user.email "you@example.com"The author email (use your GitHub email) git config --global init.defaultBranch mainName the first branch main git config --global pull.rebase falsegit pull merges (never asks how)gh auth loginLet Git sign in to GitHub (GitHub CLI)
Git: start a repository ¶ Command What it does git initMake the current folder a repository git clone <url>Download a repository from GitHub, with all its history git remote add origin <url>Connect a local repository to a GitHub one git remote -vShow the connected remotes
Git: the daily loop ¶ Command What it does git statusWhat changed? What is staged? Use it all the time git diffThe exact changes not yet staged (--staged for staged ones) git add <file> / git add .Stage a file / everything git commit -m "Message"Save the staged snapshot git commit -am "Message"Stage every modified tracked file and commit git pushSend your commits to GitHub (-u origin <branch> the first time) git pullFetch and merge others’ commits git log --oneline --graphThe history, compact, with branches
Git: branches ¶ Command What it does git branchList the local branches (* marks the current one) git switch -c <name>Create a branch and switch to it git switch <name>Switch to an existing branch git fetch originDownload new commits from GitHub, without merging git merge <branch>Merge a branch into the current one (e.g. origin/main) git branch -d <name>Delete a merged local branch
Git: undo ¶ Command What it does git restore <file>Discard uncommitted changes to a file git restore --staged <file>Unstage a file (keeps the changes) git commit --amend -m "..."Redo the last commit, before pushing it git revert <hash>A new commit that undoes an old one: safe on shared history git merge --abortCancel a merge in progress git reset --hard origin/mainMake the current branch exactly like GitHub’s main, losing local work
Command What it does git tag -a v1.0.0 -m "First release"Name the current commit v1.0.0 git push origin v1.0.0Publish the tag (tags are not pushed by git push) git tagList the tags
Merge conflict: what to do ¶ <<<<<<< HEAD
your version
=======
their version
>>>>>>> origin/mainEdit the file into the final version, and delete the three marker lines.
git add <file>
git commit -m "Merge ..." (or git merge --abort to give up)
GitHub: linking work ¶ Write this Where Effect Closes #12 (or Fixes, Resolves)Pull request description or commit message Merging into main closes issue #12 #12Anywhere Link to issue or pull request #12 @usernameIssue, PR or comment Notify that person - [ ] taskIssue or PR body A checkbox; progress shows in lists
GitHub Actions: workflow skeleton ¶ name: CI/CD # shown in the Actions tab
on: # events that start the workflow
push:
branches: [main]
tags: ["v*"]
pull_request:
branches: [main]
workflow_dispatch: # a "Run workflow" button
jobs:
test: # job name = status check name
runs-on: ubuntu-latest # a fresh virtual machine
steps:
- uses: actions/checkout@v6 # a published action
- run: pytest -v # a shell command
publish:
needs: test # only after test succeeds
if: github.event_name != 'pull_request'
runs-on: ubuntu-latest
permissions:
packages: write # what GITHUB_TOKEN may do
steps:
- run: echo "${{ github.ref_name }}" # contexts: github, secrets, matrix...Useful contexts: github.repository (owner/name), github.ref_name
(branch or tag), github.sha (commit id), github.actor (who triggered
it), github.event_name (push, pull_request...),
secrets.GITHUB_TOKEN.
Docker ¶ Command What it does docker build -t calc-app .Build an image named calc-app from the Dockerfile in . docker imagesList images docker run --rm -p 8000:8000 calc-appRun a container; port 8000 of your machine → port 8000 of the container docker run -d --name calc -p 8000:8000 calc-appThe same, in the background (-d), with a name docker ps / docker ps -aRunning / all containers docker logs calcA container’s output docker stop calc / docker rm calcStop / delete a container docker pull ghcr.io/<you>/calc-app:1.0.0Download an image from a registry docker login ghcr.ioLog in to a registry (for private images)
Dockerfile instructions ¶ Instruction Meaning FROM python:3.12-slimThe base image to start from WORKDIR /appFolder for the following instructions COPY src destCopy files from your project into the image RUN commandRun a command while building the image EXPOSE 8000Document the port the app listens on CMD ["program", "arg"]The command a container runs when it starts