Git & GitHub
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) to your local machine.
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.
This creates a hidden .git folder. Don't delete it, or you'll lose your history!
cd my-project
git init
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.
git add index.html
git status
The Stage Analogy
Imagine a theater. git add is putting actors on the stage. They aren't in the movie yet, they're just getting ready for the camera.
git commit
Committing is saving. When you commit, you're taking all the changes you staged and locking them into the project's history with a descriptive message.
Always describe what changed and why.
git commit -m "Your message here"
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.
Never work directly on main. Always create a feature/xyz branch first.
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.
git push origin main
git log
The log command shows you the history of your project. Who made what change, and when?
Interactive Practice
Ready to test your Git command knowledge? Try our interactive problems.
git log --oneline --graph --all
Use git status multiple times per hour. It's your best friend for avoiding mistakes.