Version control is a must-have skill in web development! It lets you track changes in your code, collaborate with others, and avoid "it worked on my machine" problems π
π What is Git?
Git is a distributed version control system that lets you save snapshots of your code.
π What is GitHub?
GitHub is a cloud-based platform to store Git repositories and collaborate with developers.
π οΈ Basic Git Commands (with Examples)
1οΈβ£ git init
Initialize a Git repo in your project folder.
git init
2οΈβ£ git status
Check what changes are untracked or modified.
git status
3οΈβ£ git add
Add files to staging area (preparing them for commit).
git add index.html
git add. # Adds all files
4οΈβ£ git commit
Save the snapshot with a message.
git commit -m "Added homepage structure"
5οΈβ£ git log
See the history of commits.
git log
π Using GitHub
6οΈβ£ git remote add origin
Connect your local repo to GitHub.
git remote add origin https://github.com/yourusername/repo.git
7οΈβ£ git push
Push your local commits to GitHub.
git push -u origin main
8οΈβ£ git pull
Pull latest changes from GitHub.
git pull origin main
π₯ Collaboration Basics
π Branching & Merging
git branch feature-navbar
git checkout feature-navbar
# Make changes, then:
git add.
git commit -m "Added navbar"
git checkout main
git merge feature-navbar
π Pull Requests
Used on GitHub to review & merge code between branches.
π― Project Tip:
Use Git from day 1, even solo projects! It builds habits and prevents code loss.