Have you ever saved a file as final.txt, then final_v2.txt, then final_REAL_v3.txt?
Imagine doing that with code, but you can travel back in time to any version instantly, and multiple people can work on the same file without overwriting each other.
That’s Git.
Introduction
Git is a Version Control System (VCS). It tracks changes to files over time. It is the industry standard tool for programmers. You simply cannot get a job in tech without knowing Git.
- Git: The tool installed on your laptop that tracks changes. (Like MS Word)
- GitHub: A website that hosts your Git repositories in the cloud. (Like Google Drive/Dropbox for code)
Think of Git like a video game save system:
- Commit = Creating a “Save Point”.
- Message = Naming the save (“Before Boss Fight”).
- Checkout = Loading an old save.
- Branch = A parallel timeline where you try something risky. If you die, your main game is safe.
The 3-Stage Workflow
Git adds a step between “Working” and “Saving”. It’s called Staging.
- Working Directory: Where you edit files.
- Staging Area: Where you pick which files you want to save.
- Repository (.git): Where the snapshots are stored forever.
Essential Commands
1. Setup (Do this once)
Tell Git who you are. This name will appear on your commits.
Set your username
Set your email
2. Start a Repository
Turn a folder into a Git repository.
Initialize a new repo in the current folder
3. Save Changes (The Daily Loop)
Step A: Check Status
See which files have changed
Step B: Stage Files
Add specific file to staging
Add ALL changed files to staging
Step C: Commit (Save Point)
Save staged changes with a message
4. History
View commit history (press Q to exit)
Branching and Merging
Branching lets you duplicate your code to work on a new feature (like “Dark Mode”) without breaking the working version (“Main”).
Create and Switch
List all branches
Create AND switch to a new branch called 'new-feature'
Go back to the main branch
Merge (Combine)
Once your feature works, you merge it back into main.
- Switch to main:
git switch main - Merge the feature:
git merge new-feature
Working with GitHub (Remote)
To copy your code to the cloud:
- Create a New Repository on GitHub.com.
- Connect your local folder to it:
Link local repo to GitHub URL
- Upload (Push):
Upload your commits to GitHub
- Download (Clone):
Download a repo from GitHub to your computer
Hands-On Challenge
- Create a folder
git-demoand rungit init. - Create a file
hello.txt, add text, and save. - Run
git status. See it in red? - Run
git add .thengit commit -m "First commit". - Create a branch:
git checkout -b experiment. - Edit the file. Commit.
- Switch back (
git switch main). Notice your edit is gone! - Merge it:
git merge experiment. Your edit is back.
Key Takeaways
- git init starts tracking a folder.
- git add . moves changes to the staging area.
- git commit -m “msg” saves the snapshot permanently.
- git branch lets you work safely in isolation.
- git push sends your code to GitHub.
Test Your Knowledge
Take a quick 5-question quiz to check your understanding.
Key Takeaways
git init— Start tracking any folder as a Git repository.git add .— Stage all changed files before saving.git commit -m "msg"— Save a permanent snapshot with a message.git branch/git checkout -b— Work safely in an isolated parallel timeline.git push— Upload your work to GitHub for backup and collaboration.
You have the complete Git survival kit. You can init, commit, branch, merge, and push to GitHub. Every developer on earth uses exactly these same commands, every single day.
Next Steps
- Linux Basic Commands — Git lives in the terminal; master this first
- SSH Key Management — Authenticate to GitHub without a password using SSH keys
Found this helpful? Explore more in the Tools Hub!