Why Version Control?
Git saves snapshots (commits) of your project so you can go back, compare and work in parallel. GitHub is a website that stores Git projects online and helps teams review work.
First Setup (Once)
Core Commands
| Command | What it does |
|---|---|
git init | Start tracking a folder |
git status | See what changed |
git add . | Stage all changes for the next commit |
git commit -m "message" | Save a snapshot with a message |
git log --oneline | See history in short form |
git switch -c name | Create and move to a new branch |
git merge name | Bring a branch into the current one |
git push and git pull | Send to and receive from GitHub |
A Real Session
We ran these commands in an empty test folder. Your commit codes will be different.
status: ?? index.html | log: 65ee38c Add nav, then a67994b Add home page (hashes differ on your computer) | branches: feature/menu and * main
Good Commit Messages
- Short, present tense: 'Add contact form'
- One purpose per commit
- Commit often, push at least daily
.gitignore
.env files. If it happens, treat the secret as leaked and replace it.
Branch Workflow
- Update main:
git switch mainthengit pull - Create a branch for one task:
git switch -c feature/hero - Work and commit
- Push the branch:
git push -u origin feature/hero - Open a pull request on GitHub for review
- After approval, merge it and delete the branch
Connect to GitHub
git restore file.html discards unsaved changes to a file. git revert <commit> makes a new commit that undoes an old one without rewriting history.
Practice
- Put your portfolio project under Git with three commits
- Create a branch, make a change and merge it
- Push to GitHub and open a pull request in a practice repository
Conclusion
Git keeps your history, branches let you try ideas safely and GitHub adds backup and teamwork. Commit small, write clear messages and never commit secrets.

