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
- You can undo mistakes without guessing which copy of a file is the newest.
- You can show your progress over time instead of turning in one giant last-minute upload.
- You build habits that carry directly into internships, IT work, and software jobs.
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!
git initstarts a new Git repository in the current folder.git clone <repository-url>downloads an existing repository so you can work on it locally.
Checking status, adding files, and committing changes
git status git add . git commit -m "Describe what changed" git log --onelineCopied!
A good commit message explains what changed in plain language. Short is fine if it is specific.
Pushing and pulling
git pull git pushCopied!
git pullgets the latest remote changes and brings them into your local branch.git pushsends your local commits to the remote repository.
Branching basics
git branch git branch feature-page git checkout feature-page git switch -c feature-pageCopied!
Branches let you work on a feature without disturbing your main line of development.
Merging basics
git checkout main git pull git merge feature-pageCopied!
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.htmlCopied!
git restore filename.htmldiscards local changes in that file.git restore --staged filename.htmlunstages a file while keeping the working copy changes.
Do not use restore casually. Make sure you really want to throw away that change first.
Common Git workflow
- Pull the latest changes.
- Make changes.
- Check status.
- Add files.
- Commit with a meaningful message.
- Push changes.
git pull git status git add . git commit -m "Describe what changed" git pushCopied!
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