Git - The Industry Standard
Git is a distributed version control system. This means that every developerโs computer contains the entire history of the project. It is fast, efficient, and used by millions of companies including Google, Microsoft, and Netflix.
The Git Workflowโ
Before typing commands, you must understand the Three Stages of Git. Think of it like taking a professional photo:
- Working Directory: You are posing for the photo (Writing code).
- Staging Area: You are "frozen" in the frame, but the shutter hasn't clicked (Preparing code).
- Local Repository: The photo is saved to the memory card (Saved forever).
Essential Git Commandsโ
How do you actually use it? You can choose between using the Terminal (for power users) or a GUI (for a visual experience).
- ๐ป Terminal
- ๐ฑ๏ธ Desktop App / VS Code
# 1. Start a new repository
git init
# 2. Check what has changed
git status
# 3. Add a specific file to the 'Staging Area'
git add index.js
# 4. Save the snapshot with a message
git commit -m "feat: add user login logic"
# 5. Send your code to GitHub
git push origin main
- VS Code: Click the "Source Control" icon on the left sidebar.
- Staging: Click the + icon next to the file name.
- Commit: Type your message in the box and click Commit.
- Sync: Click Sync Changes to push to the cloud.
Branching: Parallel Realitiesโ
The most powerful feature of Git is Branching.
Imagine you want to add a "Dark Mode" to your app, but you don't want to risk breaking the current working version. You create a branch.
Why CodeHarborHub Recommends Gitโ
- Offline Capability: You can save your progress while traveling or if your internet is down.
- Safety: Every "Commit" is a checksum (a unique ID). It is almost impossible to lose data or corrupt the history.
- The Ecosystem: Since Git is the standard, it integrates with every major tool like VS Code, Docker, and Vercel.
Recommended Resourcesโ
- Oh My Git!: An open-source game to learn Git visually.
- Git Cheat Sheet by GitHub: A handy PDF to keep on your desk.
Summary Checklistโ
- I understand the 3 stages: Working Directory, Staging, and Repository.
- I can initialize a project with
git init. - I know that
git addprepares my changes andgit commitsaves them. - I understand that branches allow for safe experimentation.
Always write clear commit messages. Instead of writing "Fixed stuff," write "fix: resolve login button alignment on mobile." Your future self (and your team) will thank you!