Alin Li Git

Learn version control the fun and easy way! Track your code changes like a pro.

v1.0 • Open Source Education
๐Ÿ“

1. What is Git?

โ–ผ

Git is a free, open-source version control system. It keeps track of every change you make to your files, so you can always go back to an earlier version if something goes wrong.

It was created in 2005 by Linus Torvalds, the same person who created Linux! Git is the most popular version control system in the world.

Real-Life Analogy: The Time Machine!

Imagine you're writing a story. Every time you finish a chapter, you take a photo (snapshot) of the whole notebook. If you make a mistake later, you can look back at any photo to see what the story looked like before. Git does the same for your code and files!

Another Analogy: Save Points in Video Games!

In a video game, you save your progress at certain points. If your character dies, you restart from the last save. In Git, every time you "commit," you create a save point for your project!

Fun Fact!

The name "Git" is British slang for a silly person. Linus Torvalds joked that he names his projects after himself!

๐Ÿ’ก

2. Why Use Git?

โ–ผ

Git solves some very common problems that every developer faces:

Without Git (The Old Way)

People used to save files like: project_v1.zip, project_v2_final.zip, project_v2_final_REALLY_final.zip... It was messy and confusing!

With Git, you get:

โช
Undo Mistakes
Go back to any previous version
๐Ÿ‘ฅ
Teamwork
Many people can work on the same project
๐Ÿ“‹
History
See who changed what and when
๐Ÿ”€
Branches
Try new ideas without breaking things
โฌ‡๏ธ

3. Installing Git

โ–ผ

Git works on all operating systems. Here's how to install it:

๐Ÿง

Linux (Ubuntu / Debian)

Open the Terminal and type:

$ sudo apt update $ sudo apt install git
๐ŸชŸ

Windows

Download from git-scm.com and run the installer. Keep all the default settings. This gives you "Git Bash" โ€” a special terminal for Git.

๐ŸŽ

macOS

Open the Terminal and type:

$ git --version

If Git is not installed, macOS will ask you to install it.

Check if Git is Installed

Open your terminal and type git --version. If it shows a version number, you're ready!

$ git --version git version 2.45.2
โš™๏ธ

4. First Time Setup

โ–ผ

Before using Git, you need to tell it who you are. This information appears in every commit you make.

# Set your name $ git config --global user.name "Your Name" # Set your email $ git config --global user.email "your.email@example.com" # Check your settings $ git config --list
What does --global mean?

--global means this setting applies to ALL your projects on this computer. You only need to do this once!

๐Ÿ”„

5. Git Workflow (The 3 Areas)

โ–ผ

Git has 3 important areas where your files live. Understanding these is the key to understanding Git!

The Three Areas of Git
๐Ÿ“ Working Directory
โ†’
๐Ÿ“‹ Staging Area
โ†’
๐Ÿ’พ Repository
Your files on disk
Ready to commit
Saved history
git add โ†’
git commit โ†’
Analogy: Packing a Suitcase!

Working Directory = Your room with clothes everywhere.
Staging Area = The pile of clothes you've chosen to pack.
Repository = The locked suitcase, safely stored.

git add = picking clothes from your room โ†’ pile.
git commit = putting the pile into the suitcase and locking it.

โŒจ๏ธ

6. Essential Git Commands

โ–ผ

Starting a Project

# Create a new Git repository $ git init # Or download an existing project $ git clone https://github.com/user/project.git

Making Changes

# Check which files have changed $ git status # Add a specific file to staging $ git add filename.txt # Add ALL changed files to staging $ git add . # Save (commit) with a message $ git commit -m "Add new feature"

Viewing History

# See the list of all commits $ git log # See a short version of the log $ git log --oneline # See what changed in files $ git diff
Good Commit Messages!

Always write clear commit messages that explain what you changed and why. Compare these:

โŒ "fix stuff" โ€” vague, unhelpful
โœ… "Fix login button not working on mobile" โ€” clear and useful!

Commit History Timeline
a3f2b1c
Add navigation menu
Ahmed โ€” 2 hours ago
e7d4c2a
Fix homepage layout
Fatima โ€” 5 hours ago
b1a9f3e
Create project structure
Ahmed โ€” 1 day ago
f0e2d4b
Initial commit
Ahmed โ€” 2 days ago
๐ŸŒฟ

7. Branches

โ–ผ

A branch is like a separate copy of your project where you can try new things without affecting the main code.

Analogy: A Tree!

Think of a tree. The trunk is your main project (called main branch). When you want to try something new, you grow a branch. If the branch grows well, you can merge it back to the trunk. If not, you can just cut it off!

main feature merge!
# See all branches $ git branch # Create a new branch $ git branch feature-navbar # Switch to that branch $ git checkout feature-navbar # Create AND switch in one command $ git checkout -b feature-navbar # Go back to main branch $ git checkout main # Merge feature into main $ git merge feature-navbar # Delete a branch (after merging) $ git branch -d feature-navbar
Merge Conflicts!

Sometimes two people change the same line in the same file. Git can't decide which version to keep โ€” this is called a merge conflict. You need to manually choose which changes to keep, then commit the result.

โ˜๏ธ

8. Remote Repositories & GitHub

โ–ผ

So far, everything has been on your computer (local). But what if you want to:

โ€ข Share your code with others?
โ€ข Have a backup in the cloud?
โ€ข Work on the project from another computer?

That's where remote repositories come in! Popular hosting services include GitHub, GitLab, and Codeberg (open source!).

Local โ†” Remote
๐Ÿ’ป Your Computer
Local Repo
git push โ†’
โ† git pull
โ˜๏ธ GitHub
Remote Repo
# Connect your local repo to a remote one $ git remote add origin https://github.com/user/project.git # Upload (push) your commits to GitHub $ git push -u origin main # Download (pull) new changes from GitHub $ git pull origin main # Download a project from GitHub $ git clone https://github.com/user/project.git
Open Source Alternatives!

While GitHub is the most popular, there are great open-source alternatives like Codeberg (codeberg.org) and Gitea that you can even host yourself!

๐Ÿ–ฅ๏ธ

9. Try It Out! (Interactive Terminal)

โ–ผ

Type Git commands below and see what happens! Try commands like: git init, git status, git add, git commit, git log, git branch

Alin Li Git Terminal
Welcome to Alin Li Git Simulator! Type a git command and press Enter.
Try: git init, git status, git add, git commit, git log, git branch, git help
$
๐ŸŽฏ

10. Matching Game

โ–ผ

Drag each Git command to its correct description!

Commands

What It Does

๐Ÿƒ

11. Flashcards

โ–ผ

Click each card to flip it and learn what each term means!

๐Ÿ“
Repository
Click to flip!
A folder tracked by Git. Contains all files, history, and branches of your project.
๐Ÿ’พ
Commit
Click to flip!
A snapshot of your project at a specific moment. Like a "save point" in a game.
๐ŸŒฟ
Branch
Click to flip!
A separate version of your project where you can work without affecting the main code.
๐Ÿ“‹
Staging Area
Click to flip!
The "waiting room" where you prepare files before committing them.
๐Ÿ”€
Merge
Click to flip!
Combining changes from one branch into another. Like mixing two sets of changes together.
โฌ†๏ธ
Push
Click to flip!
Uploading your local commits to a remote repository (like GitHub).
โฌ‡๏ธ
Pull
Click to flip!
Downloading new changes from a remote repository to your local computer.
๐Ÿ“
Clone
Click to flip!
Making a complete copy of a remote repository onto your local computer.
๐Ÿ“

12. Final Quiz

โ–ผ

Test your knowledge! Choose the correct answer for each question.

๐Ÿ“Œ

13. Git Cheat Sheet

โ–ผ

Keep this handy! These are the most important Git commands you'll use:

git init
Start a new Git repository
git clone <url>
Copy a remote repository
git status
See what files have changed
git add <file>
Stage a file for commit
git add .
Stage ALL changed files
git commit -m "msg"
Save staged changes
git log
View commit history
git log --oneline
Short version of log
git diff
See what changed in files
git branch
List all branches
git branch <name>
Create a new branch
git checkout <branch>
Switch to a branch
git checkout -b <name>
Create + switch branch
git merge <branch>
Merge branch into current
git remote add origin <url>
Connect to remote repo
git push
Upload commits to remote
git pull
Download changes from remote
git stash
Temporarily save changes