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.
๐ฌ React โค๏ธ for more!