Git Cheatsheet

A student-friendly Git reference for class projects, team work, and personal coding practice. The goal is to keep the basics clear so you can track changes with confidence and recover from simple mistakes without panic.

What Git is

Git is a version control system. It tracks file changes over time so you can see history, compare versions, work on features safely, and collaborate with other people without overwriting each other by accident.

Git vs. GitHub

Git

The tool on your computer that tracks versions and commits.

GitHub

A hosting service for Git repositories with pull requests, issues, and collaboration tools.

Why the difference matters

You can use Git without GitHub, but many classes and teams use GitHub to share repositories online.

Why students should learn Git

Initial setup

Run these once on a new machine so your commits are labeled correctly.

git config --global user.name "Your Name"
git config --global user.email "your.email@example.com"
Copied!

Creating or getting a repository

git init
git clone <repository-url>
Copied!

Checking status, adding files, and committing changes

git status
git add .
git commit -m "Describe what changed"
git log --oneline
Copied!

A good commit message explains what changed in plain language. Short is fine if it is specific.

Pushing and pulling

git pull
git push
Copied!

Branching basics

git branch
git branch feature-page
git checkout feature-page

git switch -c feature-page
Copied!

Branches let you work on a feature without disturbing your main line of development.

Merging basics

git checkout main
git pull
git merge feature-page
Copied!

A merge brings work from one branch into another. If Git reports conflicts, stop and resolve them carefully instead of guessing which version should win.

Undoing simple mistakes

git restore filename.html
git restore --staged filename.html
Copied!

Do not use restore casually. Make sure you really want to throw away that change first.

Common Git workflow

  1. Pull the latest changes.
  2. Make changes.
  3. Check status.
  4. Add files.
  5. Commit with a meaningful message.
  6. Push changes.
git pull
git status
git add .
git commit -m "Describe what changed"
git push
Copied!

Common errors and what they mean

Message or problem What it usually means
fatal: not a git repository You are in the wrong folder, or Git has not been initialized there.
nothing to commit, working tree clean There are no tracked changes waiting to be committed. Run git status and confirm what you expected to change.
Updates were rejected because the remote contains work that you do not have locally Someone else pushed first. Run git pull, resolve any conflicts, then push again.
Merge conflict Git could not combine two sets of edits automatically. Open the conflicted files and resolve them deliberately.

Quick reference

Task Command
Check status git status
Add all current changes git add .
Create a commit git commit -m "Describe what changed"
View short history git log --oneline
Get remote changes git pull
Send local commits git push
Create and switch to a branch git switch -c feature-page
Undo a local file change git restore filename.html

Related pages

Vim, PowerShell, and Curl