Git Cheatsheet
AI-Assisted Programming for PhD Researchers
One page of the Git and uv commands you’ll actually use during the labs. Keep this open in a second window; you don’t need to memorize any of it.
Identity
Set this once per machine, before your first commit.
| Command | What it does |
|---|---|
git config --global user.name "Your Name" |
Sets the name attached to your commits |
git config --global user.email "you@example.com" |
Sets the email attached to your commits |
Everyday loop
The cycle you repeat constantly: check status, stage, commit.
| Command | What it does |
|---|---|
git init |
Turns the current folder into a new Git repository |
git clone URL |
Copies a remote repository to your machine |
git status |
Shows what’s changed, staged, and untracked |
git add <file> |
Stages a file’s changes for the next commit |
git add -p |
Stages changes interactively, hunk by hunk |
git commit -m "message" |
Records the staged changes as a new commit |
Looking around
Inspect history and changes without modifying anything.
| Command | What it does |
|---|---|
git log --oneline --graph |
Compact, one-line-per-commit history with branch graph |
git diff |
Shows unstaged changes in the working directory |
git diff --staged |
Shows changes that are staged for the next commit |
git show HEAD |
Shows the full commit at HEAD (message + diff) |
Undoing
Safe first, destructive last: these go roughly in order of risk.
| Command | What it does |
|---|---|
git restore <file> |
Discards unstaged changes to a file, back to the last commit |
git restore --staged <file> |
Unstages a file, keeping the edits in your working directory |
git reset --soft HEAD~1 |
Undoes the last commit but keeps its changes staged |
Branches
| Command | What it does |
|---|---|
git switch -c <name> |
Creates a new branch and switches to it |
git switch <name> |
Switches to an existing branch |
git merge <name> |
Merges <name> into the current branch |
git branch -d <name> |
Deletes a branch (only if it’s already merged) |
Remotes & GitHub
A remote is a copy of the repository on a server (for us: GitHub). Push uploads your commits; pull downloads and merges what’s new.
| Command | What it does |
|---|---|
git clone <url> |
Copies a remote repository into a new local folder |
git remote -v |
Shows which remote(s) this repository talks to |
git push |
Uploads your new commits to the remote (first time on a new branch: git push -u origin <branch>) |
git pull |
Downloads new commits from the remote and merges them into your branch |
To publish a repo that only exists on your machine (your capstone): create an empty repository on GitHub, then git remote add origin <url> && git push -u origin main.
Worktrees
A worktree lets you have two branches checked out at the same time, in separate folders, handy for running an AI agent on one branch while you keep working on another.
| Command | What it does |
|---|---|
git worktree add ../wt-branch <branch> |
Checks out an existing <branch> into a new sibling folder ../wt-branch |
git worktree add -b <branch> ../wt-branch |
Creates a new <branch> and checks it out into ../wt-branch |
git worktree list |
Lists all worktrees attached to this repository |
git worktree remove <path> |
Removes a worktree (the branch itself is untouched) |
.gitignore patterns
List files and folders Git should never track: build artifacts, virtual environments, secrets. One pattern per line.
| Pattern | Matches |
|---|---|
__pycache__/ |
Any folder named __pycache__, anywhere in the repo |
*.pyc |
Any file ending in .pyc |
.venv/ |
A local virtual environment folder |
.env |
A local environment/secrets file |
data/raw/*.csv |
CSVs directly under data/raw/ (but not subfolders) |
The same in Zed
Most of the everyday loop also works from Zed’s UI (Lecture II shows it). Zed and the CLI operate on the same repository, so mix them freely.
| Command line | In Zed |
|---|---|
git status |
Git Panel (git panel: toggle focus, or the Git icon in the status bar) |
git add <file> |
Checkbox next to the file in the Git Panel (space toggles) |
git add -p |
Stage hunk by hunk in the Project Diff |
git commit -m "..." |
Commit box at the bottom of the Git Panel, cmd-enter / ctrl-enter |
git diff / git diff --staged |
Project Diff (git: diff, ctrl-g d) |
git restore <file> |
git: restore file from the Command Palette |
git switch -c / git switch |
git: branch creates one; git: switch opens the branch picker |
git fetch / git push / git pull |
Buttons in the Git Panel, or git: fetch / git: push / git: pull |
git worktree add / remove |
git: worktree picker: create, open in a new window, delete |
No UI equivalent (use the terminal): git init, git clone, git log, git show, tags, and git merge.
Python / uv
uv manages Python and project dependencies for every lab. See the Setup page for installation.
| Command | What it does |
|---|---|
uv --version |
Confirms uv is installed and prints its version |
uv init --lib |
Creates a new Python library project (with pyproject.toml) |
uv add --dev <package> |
Adds <package> as a development dependency |
uv run <command> |
Runs <command> inside the project’s managed environment |
uv run pytest |
Runs the test suite inside the project’s managed environment |