ping·aiCSTU · CSE 642 · Foundations · Git and GitHub
Part A · The words

Why Git and GitHub

Save versions, share them, and undo mistakes.

Git records versions of a project on your computer. GitHub keeps copies online so people can share, review and combine work. The GitHub CLI, gh, lets you use GitHub from the terminal.

You will use a handful of commands. Learning the right words lets a Coding Agent App do the rest with you.

Slide 1 of 15

Read this deck as an article

The same content as the slides above, in one page.

Why Git and GitHub

Save versions, share them, and undo mistakes.

Git records versions of a project on your computer. GitHub keeps copies online so people can share, review and combine work. The GitHub CLI, gh, lets you use GitHub from the terminal.

You will use a handful of commands. Learning the right words lets a Coding Agent App do the rest with you.

Two places you type

A terminal takes exact commands. A Coding Agent App takes plain-language prompts.

The Terminal

A text window where you type exact commands. The shell inside it runs each command the moment you press Enter.

  • Spelling and spacing must be exact.
  • macOS and Linux use zsh or bash. Upper and lower case matter there: Git is not git.
  • Windows uses PowerShell. It does not care about case in command names, but type them as shown anyway.
  • Names inside a command, such as Linux file paths, branch names and image names, can be case-sensitive in any shell.
  • The two kinds of shell have different commands: ls -la works in zsh and bash, while PowerShell uses Get-ChildItem -Force.

Terminal command, macOS and Linux (zsh or bash, case-sensitive): ls -la

Terminal command, Windows PowerShell (command names are not case-sensitive): Get-ChildItem -Force

A Coding Agent App

It looks like a chatbot, but it does much more: it can read your project files, run commands, edit code and use tools, and it often asks your permission first. Product names and features change fast and differ a lot, so these decks use one group name for all of them.

Examples: Kiro, Claude Code Desktop, GitHub Copilot's desktop app, Google Antigravity, the Codex and ChatGPT desktop apps, OpenCode, Hermes, LangChain's Deep Agents desktop app, and others. Which one you use does not matter here.

  • Plain language is fine. Say what you want, and use the right names for things.
  • Capital letters and small slips are forgiving; the meaning is what counts.
  • It may run terminal commands for you. Read what it proposes, especially anything that deletes files or sends data.
  • Pasting a command into the prompt does not guarantee it runs as typed. Ask for the result you want, or ask the app to explain the command first.
Prompt for a Coding Agent App: “What changed in my project since the last commit? Explain it in plain words.”

The same job, two ways

Terminal command, Any shell: git status

In a terminal you type the exact command. In a Coding Agent App you describe what you want.

Eight words, part 1

Each card gives the word, what it means, and a sentence you can say to a Coding Agent App.

Repository (repo)
A project folder that Git tracks, with its whole history.
Prompt for a Coding Agent App: “Is this folder a Git repository?”
Commit
A saved snapshot of your files with a short message.
Prompt for a Coding Agent App: “Commit my changes with a clear message.”
Branch
A separate line of commits, so you can try something without touching the main version.
Prompt for a Coding Agent App: “Make a new branch for this change.”
Tag
A fixed name for one commit. A branch moves as you commit; a tag does not.
Prompt for a Coding Agent App: “Check out the code at tag CP1-start.”

Eight words, part 2

Clone
Download a repository, with its history, to your computer.
Prompt for a Coding Agent App: “Clone this repository into my projects folder.”
Remote (origin)
A copy of the repository on another computer, usually GitHub. origin is its usual name.
Prompt for a Coding Agent App: “Which remote does this repo push to?”
Stage
Choose which changes go into the next commit.
Prompt for a Coding Agent App: “Stage only the files I changed in app/.”
Pull request
A proposal on GitHub to merge one branch into another, with a place to review it.
Prompt for a Coding Agent App: “Open a pull request with a summary of my change.”

Wrong word, right word: “the Git file I downloaded” is a repository; “my save point” is a commit.

The everyday loop

Run these inside the project folder.

Terminal command, Any shell: git status

What changed? Safe to run any time. Shows changed files and which branch you are on.

Terminal command, Any shell: git add -A

Stage everything Marks all current changes for the next commit.

Terminal command, Any shell: git commit -m "message"

Save a snapshot Write the message so you can understand it in a month.

Terminal command, Any shell: git log --oneline

See the history One line per commit, newest first.

Terminal command, Any shell: git push

Send commits to the remote Needs write access to that repository.

Terminal command, Any shell: git pull

Bring in new commits Do it before you start work on a shared branch.

The commit graph

Commits are the circles; commands add them or move the labels. The word on an arrow is the command that made it. Press Next command and watch.

Each commit is a node in a graph. An arrow joins a commit to the commit made after it, and the label on the arrow is the command that made it. These steps show the graph after each command.

  1. git clone https://github.com/owner/repo.git: Clone downloads the whole history: three commits, A, B and C. You start on main, and origin/main shows where main is on GitHub.
  2. git switch -c my-site: A new branch is only a new label on the commit you are on. Nothing is copied. HEAD, the commit you are working on, now follows my-site.
  3. git add -A && git commit -m "Add my name": A commit adds one circle whose parent is the commit you were on. The branch label you are on moves forward to it. main stays where it was.
  4. git commit -m "Add contact section": Another commit adds E after D. my-site moves again. Every commit remembers its parent, which is how Git keeps the history in order.
  5. git push -u origin my-site: Push sends your new commits to GitHub and moves the remote label origin/my-site to match. No new commit is made; only a label moves.
  6. git switch main && git pull: While you worked, a teammate added commit F to main on GitHub. Pull brings F down and moves main forward to it. Now the history has split into two lines.
  7. git merge my-site: A merge adds commit M with two parents, F and E. It joins the two lines of work. main moves to M. On GitHub this step is usually a reviewed pull request.
  8. git push: Push moves origin/main to M, so GitHub's main now includes your work.
  9. git tag v1.0: A tag is a fixed name on one commit. Branch labels move as you commit; the tag v1.0 stays on M for good.

A branch is only a label on a commit. A command either adds a commit or moves a label.

Branches, tags and “detached HEAD”

Terminal command, Any shell: git switch -c my-site

Make a new branch and move to it Do this right after cloning a tag so your edits have a home.

Terminal command, Any shell: git switch main

Go back to another branch Commit or stash your changes first.

Terminal command, Any shell: git clone --branch CP1-start URL

Clone straight to a tag A tag is a fixed starting point: everyone gets the same code.
“You are in 'detached HEAD' state”
You are on a tag or commit, not a branch Not an error. Run git switch -c name to start a branch there.

Getting a project: clone

  • git clone https://github.com/owner/repo.git downloads a repository into a new folder named repo.
  • gh repo clone owner/repo does the same through the GitHub CLI.
  • Public repositories need no sign-in to clone. You only sign in to push or to reach private repositories.
  • Then cd repo to go into the folder, and git status to check the state.

Say to your AI: “Clone this repository and tell me which branch I am on.”

The GitHub CLI (gh)

GitHub from the terminal.

Terminal command, Any shell: gh auth login

Sign in Follow the prompts; it opens a browser. Needed for pushing and private repos.

Terminal command, Any shell: gh auth status

Am I signed in? Shows the account without printing your token.

Terminal command, Any shell: gh repo clone owner/repo

Clone a repository Same result as git clone.

Terminal command, Any shell: gh pr create

Open a pull request Run it from your branch after you push.

Terminal command, Any shell: gh pr view --web

Open the pull request in your browser Good for reviewing and sharing the link.

Terminal command, Any shell: gh --version

Is it installed? If not found, install it and open a new terminal.

The open-source cycle

How most shared projects change, step by step.

1 · Fork or clone
Get your own copy A fork is your own copy of a repository on GitHub.
2 · Branch
Start a branch for one change Keep each change small and named for its purpose.
3 · Commit
Save your work in steps Clear messages help reviewers.
4 · Push
Send the branch to GitHub git push -u origin your-branch the first time.
5 · Pull request
Ask for review Describe what changed and how you tested it.
6 · Review and merge
Discuss, fix, merge The maintainer merges it into the main branch.

Optional: worktrees

Two folders, one repository, two branches at once.

A worktree is an extra folder checked out from the same repository on a different branch. You can work on a second idea, or run a long test, without stashing or switching in your main folder.

Coding Agent Apps use worktrees to try changes in a separate folder so your main copy stays untouched.

Optional: worktree commands

Terminal command, Any shell: git worktree add ../fix-typo -b fix-typo

Make a new folder on a new branch The new folder sits next to your project folder.

Terminal command, Any shell: git worktree list

See every worktree Shows each folder and its branch.

Terminal command, Any shell: git worktree remove ../fix-typo

Remove the extra folder Run it when the branch is merged or abandoned.

A branch can be checked out in only one worktree at a time.

Common problems and the words to use

fatal: not a git repository
You are in the wrong folder Run pwd, then cd into the project folder.
Your local changes would be overwritten
You have unsaved changes in the way Commit them, or put them aside with git stash.
failed to push some refs
The remote has commits you do not have Run git pull first, then push again.
Authentication failed / Permission denied
You are not signed in, or you lack write access Run gh auth login. For someone else's repo, fork it first.
CONFLICT (merge conflict)
Two changes touch the same lines Open the marked files, choose the lines to keep, then commit. Your AI can walk you through it.
“I committed a key or password”
Treat it as leaked Revoke the key at its provider. Deleting the file does not remove it from history.

Say it to your Coding Agent App

Name the branch or tag, and paste the exact error.

Prompt for a Coding Agent App: “Run git status and explain it in plain words.”
Prompt for a Coding Agent App: “Create a branch called my-site from the CP1-start tag and switch to it.”
Prompt for a Coding Agent App: “git push fails with: <paste the exact error>. What does it mean and what is the smallest fix?”
Prompt for a Coding Agent App: “Write a commit message for these changes, then show me what will be committed first.”
  • Keep .env files and keys out of Git: they belong in .gitignore. Never paste keys into a prompt.