Git
Master the industry standard for version control. Learn to track changes, collaborate seamlessly, and manage your project history like a pro.
What is Git?
Git is a distributed version control system. It's like a time machine for your code, allowing you to save "checkpoints" and travel back if something breaks.
Save States
Think of Git like "Save Slots" in a video game. You can always go back to a previous state if you lose.
Multiplayer
Git lets multiple developers work on the same files without overwriting each other's work.
git clone
Cloning is how you download a project from a remote server (like GitHub) directly to your local machine.
Repository = Folder
Don't let the technical jargon confuse you. When you hear the word "Repository" (or "Repo"), just think of it as a regular folder. That's all it really is!
Remote to Local
The flow is simple: you grab the URL of the remote repository from GitHub, then you paste it into your local terminal using the git clone command to pull down the latest changes.
The Franchise Analogy
Think of GitHub as the "Main Branch" of a store. Running git clone is like opening up "your own branch" of that store locally on your own computer.
git clone https://github.com/user/repo.git
git init
If you have a local project that isn't on GitHub yet, use git init to start tracking it.
Initialize
"Init" simply stands for Initialize. Running this command converts a regular, boring folder into a full-fledged Git Repository capable of tracking file changes.
The Invisible Magic
Git does its tracking by creating a hidden .git folder inside your directory. You won't see it normally, but it's there. Never delete it, or you will lose your entire project history!
Terminal Comfort
Get comfortable using the terminal to create your folders instead of right-clicking. It is much faster and standard practice in the industry.
mkdir GitSample
cd GitSample
git init
The Power of VS Code
Once initialized, VS Code's built-in Source Control features will light up. It is highly recommended to use VS Code specifically for how seamlessly it visualizes file changes and Git tracking.
git add
Before you save your work, you have to "stage" it. This lets you choose exactly which changes you want to include in your next save state.
The Purpose of Staging
git add does not save your work. Instead, it prepares and selects which changes you want to include in your next save. Think of it like packing a suitcase: you are deciding what items go in before you actually zip it shut.
What "U" Means
In VS Code, when you create a new file, a U appears next to it. This stands for Untracked, meaning Git does not know about this file yet until you stage it.
The Magic Dot (.)
When you run git add ., the dot literally translates to "this directory". It tells Git to grab every single untracked or modified file in your current folder and stage them all at once.
Granular Control
You don't have to add everything! You can stage a single file by typing its name directly: git add index.html. This gives you exact control over what gets saved.
The Temporary Snapshot
The staging area acts as a temporary snapshot or safety net. You can put files there, review them, and if you realize you made a mistake, you can remove them before making the change permanent.
git commit
Committing is saving. When you commit, you're taking all the changes you staged and locking them into the project's history.
The "Memory"
A commit is essentially a "locked memory." You take the temporary snapshots you placed in the staging area and lock them securely into the permanent history log of your project.
The -m Flag
When typing git commit -m, the -m simply stands for message. It tells Git that the string following it is your commit summary.
Context is Key
The code shows what changed, but the commit message tells the reviewer why it changed. If another team member reviews your work, your message saves them hours of confusion.
The Golden Rule
Always be as descriptive as possible. Instead of writing "fixed bug", write "fixed navbar overlap issue on mobile screens".
Still Local!
Even after you commit, your code is still just on your computer. It is not on GitHub yet. It is just officially packaged and ready to be pushed.
The Team Workflow
Commits organize a team's progress sequentially. When Member A finishes their task, they commit, push, and go to review. Then Member B pushes their commit. It creates an organized track record of who did what, and when.
git commit -m "feat: add user login flow"
Branching
Branches let you work on a new feature in a separate "universe" without affecting the main code. Once you're done, you "merge" it back.
The Tree Analogy
"Imagine there's a tree... the main is the big trunk, and the branches still originate from it." Branches allow your project to grow in different directions safely.
Isolation & Conflict Prevention
Branches exist so multiple team members can work simultaneously. If Member 1 and Member 2 both work directly on `main`, their code will clash constantly. Branches act as isolated "sandboxes" preventing conflicts until the code is ready to merge.
Franchise Analogy
If the remote repository is the "main store", creating branches is like opening new franchise locations to do independent work.
Listing Branches
Need to see what branches you currently have? Just run the command without any arguments to list them out.
Local vs Remote
Just because you created a branch on your computer (Local) doesn't mean it exists on GitHub (Remote) yet. You have to push it up to connect them.
Pro Workflow
Never work directly on main. The industry standard is to always create a feature/xyz branch before writing any code.
git switch -c feature-name
# Code your feature...
git switch main
git merge feature-name
git push
Pushing uploads your local commits to a remote server like GitHub. This is how you back up your work and share it with teammates.
The Final Hand-off
git push is the official step where your local, committed changes are finally uploaded to the remote repository. It bridges the gap between your computer and the cloud.
Reviewer Visibility
Reviewers cannot see code that only exists on your computer. Pushing is what finally makes your work, and the commit messages you wrote, visible to the rest of the team for review.
Task Completion
Running this command marks the end of your immediate task cycle. Once pushed, your job is done and the ball is squarely in the reviewer's court.
git push origin main