Git & GitHub for Web Projects
Why Git?
Git saves snapshots (commits) of your project, so you can undo mistakes, try ideas on branches and collaborate. GitHub hosts your repositories online and is your portfolio as a developer.
Daily workflow
git init
git add .
git commit -m "Add navbar"
git branch -M main
git remote add origin https://github.com/you/site.git
git push -u origin main
Then for each feature: git switch -c feature/contact-form → commit → push → open a Pull Request → merge.
.gitignore for web projects
node_modules/
dist/
.env
.DS_Store
Good habits
- Small commits with clear messages in the imperative: "Fix mobile menu overflow".
- Pull before you start (
git pull) to avoid conflicts. - Never commit
.envfiles or API keys. If you do, change the key immediately; deleting the commit isn't enough.
Free deploys from GitHub
GitHub Pages, Netlify, Vercel and Cloudflare Pages can deploy automatically every time you push to main, and give each Pull Request its own preview link.
Example
git init
git add .
git commit -m "Initial portfolio site"
git branch -M main
git remote add origin https://github.com/your-name/portfolio.git
git push -u origin main
# New feature on its own branch
git switch -c feature/dark-mode
git add .
git commit -m "Add dark mode toggle"
git push -u origin feature/dark-mode
# → open a Pull Request on GitHub, review, merge
# 💻 Terminal commands — run them on a computer