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¶
Run:
git --versionIf macOS offers to install its command-line developer tools, accept that installation, then open a fresh terminal and run the check again.
Try git --version first. If Git is absent, install it with your
distribution’s package manager, for example sudo apt install git on
Ubuntu/Debian or sudo dnf install git on Fedora. These commands install a
named system package; do not generalize sudo to ordinary course commands.
If you installed Git Bash in Chapter 1, Git is already installed. Open Git Bash and run:
git --versionIf the command is absent, install Git for Windows using its default options and reopen Git Bash.
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 --listUse 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 statusFollow 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¶
| Step | Command | Question it answers |
|---|---|---|
| Inspect | git status | Which files changed, and what is staged? |
| Review | git diff | What changed in tracked text files? |
| Stage | git add <path> or git add -A | Which changes belong in this commit? |
| Record | git commit -m "message" | What project state am I preserving? |
| Share | git push | Which 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:
| Command | What it stages | When to use it |
|---|---|---|
git add analysis.ipynb README.md | Only the named paths | The commit should contain a specific subset of the work. |
git add . | Changes at and below the current directory | You are at the repository root and all visible changes belong to one coherent checkpoint. |
git add -A | All additions, modifications, and deletions anywhere in the repository | The 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 pushRun 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¶
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.
On that repository’s GitHub page, copy its HTTPS clone URL.
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 pushOpen 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 statusDuring 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 pushGood messages name the outcome:
Implement all four transit overlap casesAdd boundary checks for flux modelInterpret HR diagram radius trends
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/fileThis 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/fileThis 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 -5Do 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¶
git --versionworks.My Git name and email are configured.
gh auth statusshows the GitHub account I use for the course.I can distinguish working, staged, committed, and pushed changes.
I use
git status, choose an appropriate staging scope (<path>,., or-A), and inspect the staged result before each commit.I cloned the Project 1 repository I will submit through Canvas (or the Classroom50 repository when one was assigned).
My saved readiness notebook is visible on GitHub.
The P1 readiness check is green.