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) |
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 <branch> into a new sibling folder ../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) |
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 |