Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Chapter 3: Git, GitHub, and Project Repositories

Record, push, and verify your work

Git records snapshots of a project on your computer. GitHub stores the commits you push to a remote repository. Classroom50 may distribute an individual course repository; for Project 1, Canvas accepts the URL of your GitHub repository as the submission route.

Step 1: Install and verify Git

macOS
Linux
Windows

Run:

git --version

If macOS offers to install its command-line developer tools, accept that installation, then open a fresh terminal and run the check again.

Step 2: Identify your commits

Configure the name and email that Git writes into new commits:

git config --global user.name "Your Name"
git config --global user.email "your-email@example.com"
git config --global init.defaultBranch main
git config --global --list

Use an email connected to your GitHub account, or a GitHub-provided private commit email if you do not want a personal address in commit metadata.

Step 3: Sign in safely

Create a GitHub account if you do not already have one and enable two-factor authentication. Joining the course does not require the Student Developer Pack, GitHub Copilot, or a classic personal access token.

Activate the course environment and use the installed GitHub CLI to configure one cross-platform HTTPS credential path:

conda activate comp521
gh auth login --web --git-protocol https
gh auth setup-git
gh auth status

Follow the browser or device-code prompt and sign into the GitHub account you will use for the course. gh auth setup-git configures GitHub CLI as Git’s credential helper; gh auth status confirms the account and reports where the credential is stored. If Classroom50 is used for a project, its invitation will separately ask you to authorize it with that GitHub account.

The five-part Git loop

StepCommandQuestion it answers
Inspectgit statusWhich files changed, and what is staged?
Reviewgit diffWhat changed in tracked text files?
Stagegit add <path> or git add -AWhich changes belong in this commit?
Recordgit commit -m "message"What project state am I preserving?
Sharegit pushWhich local commits am I sending to GitHub?

git add does not upload anything. It selects content for the next commit. git commit records that staged state locally. git push transfers commits to GitHub.

Choose the staging scope deliberately

All three of these forms are useful:

CommandWhat it stagesWhen to use it
git add analysis.ipynb README.mdOnly the named pathsThe commit should contain a specific subset of the work.
git add .Changes at and below the current directoryYou are at the repository root and all visible changes belong to one coherent checkpoint.
git add -AAll additions, modifications, and deletions anywhere in the repositoryThe whole repository state belongs in the checkpoint, even if your terminal is in a subdirectory.

git add . and git add -A are normal course-workflow commands, not mistakes. Their scope is simply broader than naming files. Inspect that scope before and after staging:

git status
git diff
git add .
git status
git diff --staged
git commit -m "Complete transit branch checks"
git push

Run git add . from the repository root when you mean “this whole project.” If unrelated files appear in git status, stage named paths instead. For readable text files, git diff --staged shows the exact staged lines. A notebook is structured JSON, so git diff --staged --stat plus a clean restart-and-run check is usually more useful. Never stage credentials, excluded datasets, or machine-specific files merely because a broad command found them.

Project repositories and Classroom50

For Project 1, create or use the GitHub repository you will submit through the Canvas Project 1 assignment. Classroom50 can also create an individual repository when its invitation is available. Its current student web guide describes GitHub authorization and repository creation. The course-specific project brief and Canvas announcement take precedence over a generic service example or screenshots from another course.

Create or accept, then clone Project 1

  1. If a Classroom50 invitation is available, follow its prompts and open the repository assigned to your GitHub account. Otherwise, create/use the individual GitHub repository you will link in Canvas.

  2. On that repository’s GitHub page, copy its HTTPS clone URL.

  3. In Git Bash or Terminal, go to the parent directory where you keep course projects, then clone the URL:

    git clone PASTE_THE_HTTPS_URL_HERE
    cd NAME_OF_THE_CLONED_FOLDER
    git status

Use the actual URL and folder name shown for your repository. The Project 1 brief and Canvas assignment own the active submission route.

Complete the Project 1 GitHub Repository Check

Due Fri Aug 28 at 11:59 pm PT. In the cloned repository’s README.md, change the repository-check box from [ ] to [x]. Then return to the terminal in that repository and run:

git status
git add README.md
git diff --staged
git commit -m "Complete Project 1 repository check"
git push

Open the repository on GitHub and verify that the new commit appears.

That one visible commit records completion; there is no separate upload or automated readiness test. For later assignments, follow the exact project brief.

A daily project workflow

At the beginning of a work session:

cd path/to/your/project
conda activate comp521
git status

During the session, work in one coherent slice and run the smallest relevant check. At a useful checkpoint, choose a staging command whose scope matches the checkpoint:

git status
git diff
git add .

From the repository root, git add . stages the project changes shown by git status. Use git add -A when you intend to stage the complete repository state from any subdirectory, or name paths when the commit should contain only part of the work. Then inspect and record the staged state:

git status
git diff --staged
git commit -m "Explain the completed change"
git push

Good messages name the outcome:

Messages such as stuff, done, or final final do not help you recover the reasoning later.

When should you pull?

git pull incorporates commits already on GitHub that your local branch does not have. In an individual course repository, you usually need it only if you edited on GitHub, worked from another computer, or the instructor explicitly added a commit. Do not use pull as a generic response to every push error; read the error first.

Safe beginner recovery

Always start with git status. If you are unsure whether work is recoverable, make a copy outside the repository or ask for help before running an undo command.

I staged the wrong file

git restore --staged path/to/file

This removes the file from the next commit but keeps its working copy.

I want to discard an uncommitted edit to one tracked file

First inspect git diff path/to/file. If you are certain none of those edits should survive:

git restore path/to/file

This is destructive for that file’s uncommitted edits. It does not recover untracked files.

A committed change needs to be undone

Locate it with git log --oneline. In a shared or already-pushed history, git revert COMMIT_ID creates a new commit that reverses the selected change. Ask for help before doing this the first time.

A push is rejected

Save the entire error and run:

git status
git remote -v
git log --oneline -5

Do not use --force or reset --hard. Those commands can discard work or rewrite shared history and are not part of the course’s normal recovery path.

A credential or secret entered a commit

Revoke or rotate the credential immediately, even if you have not pushed it. Then contact the instructor for history-cleanup help. Deleting the visible line does not make an exposed secret safe again.

Individual work and collaboration

Course projects may include paired scientific discussion, but each student writes, understands, and submits their own implementation and interpretation. Do not add classmates as code collaborators or exchange solution repositories unless a project brief explicitly changes that rule. See the project collaboration policy.

Readiness checklist

References