Brtest Tutorial
Git & Version Control
Version control tracks changes to your code over time so you can collaborate, experiment safely, and roll back mistakes. Git is the most popular version control system and works locally on your computer as well as with remote services like GitHub, GitLab, and Bitbucket.
🔧 Install & First-Time Setup
Install Git from your package manager or official site. Then set your name and email (used in commit history):
Configure Git
git --version
git config --global user.name "Your Name"
git config --global user.email "you@example.com"
git config --global init.defaultBranch main
git config --global core.editor "code --wait"
Tip: Use git config --global -l to see your current settings.
📁 Create a Repository
A repository (repo) is a folder tracked by Git.
Start New Repo
mkdir my-site
cd my-site
git init
echo "# My Site" > README.md
git status
Tip: Create a .gitignore to exclude files (e.g., node_modules, build folders, secrets).
.gitignore (example)
# dependencies
node_modules/
# builds
dist/
build/
# system files
.DS_Store
# env
.env
📝 Stage & Commit Changes
Git tracks changes in three places: working directory → staging area → repository.
Stage & Commit
git add index.html css/style.css
git commit -m "Add homepage and styles"
git log --oneline
Good messages: Use imperative tone: Add header nav, Fix form validation, Refactor gallery.
🌿 Branching & Merging
Branches let you develop features without touching main. Merge when ready.
Feature Branch Workflow
git switch -c feature/navbar
# ...edit files...
git add .
git commit -m "Implement responsive navbar"
git switch main
git merge feature/navbar
Resolve Merge Conflicts (basic)
# Open the conflicted files, keep desired changes, remove conflict markers:
# <<<<<<< HEAD
# (your changes)
# =======
# (their changes)
# >>>>>>> branch-name
git add conflicted-file.html
git commit -m "Resolve merge conflict in header"
🌐 Connect to a Remote (GitHub/GitLab)
Push your local repo to a remote service to back it up and collaborate.
Add Remote & Push
git remote add origin https://github.com/yourname/my-site.git
git branch -M main
git push -u origin main
Clone Existing Repo
git clone https://github.com/yourname/my-site.git
cd my-site
git pull # fetch and merge remote changes
git push # upload your new commits
🚀 Typical Web Flow (Solo)
- Pull latest (
git pull). - Branch for a task (
git switch -c feature/foo). - Code, then commit in small steps.
- Merge back into
main. - Push to remote and deploy.
👥 Team Flow (Pull Requests)
Teams often use PRs (pull/merge requests) for code review.
- Create a branch and push it.
- Open a PR on the platform (GitHub/GitLab).
- Request review, address feedback.
- Squash/rebase if needed, then merge.
Tip: Keep branches short-lived. Small, focused PRs are easier to review and revert.
🔄 Undo & Fix Mistakes
Everyone makes mistakes; Git makes it easy to recover.
Common “Oops” Commands
# Unstage a file (keeps changes)
git restore --staged file.css
# Discard local changes in a file (cannot be undone)
git restore file.css
# Amend last commit message/files
git commit --amend
# Go back to a previous commit (safe, keeps history)
git revert <commit-hash>
🏷️ Tags & Releases
Use tags to mark versions (e.g., v1.0.0) and create release notes.
Create & Push Tags
git tag v1.0.0
git push origin v1.0.0
git tag -l
📦 Stash (Shelve WIP)
Temporarily save changes without committing.
Stash Workflow
git stash
git pull
git stash pop
✅ Best Practices
- Commit often with clear messages.
- Use branches for features and fixes.
- Keep
mainalways deployable. - Protect
mainwith reviews/status checks (on the platform). - Use
.gitignoreand never commit secrets (.env). - Tag releases and keep a CHANGELOG.
🚀 Bonus: Deploy with Git
Many hosts support deploying on git push, or via CI/CD.
Basic CI/CD Concept (Pseudo)
# On push to main:
# 1) Install deps
# 2) Build
# 3) Upload build (or restart server)
Next step: Continue to “WD Git: GitHub Flow” for a step-by-step PR tutorial and to “WD Git: Deploy with Git” to connect your repo to hosting.