Skip to main content
Zhimalab
中文
7 Days · Interactive
0%
🎓 Interactive tutorial

Git Quick Start
7-Day Interactive Course

Start from zero and master the core skills of Git version control in 7 days through hands-on terminal practice, diagrams and quizzes. Ideal for second-year college students and programming beginners.

7
days of lessons
35+
commands hands-on
21
quiz questions
1
terminal simulator

Day 1Version control & Git

A version control system (VCS) is an essential tool in software development — it records every change to your files so you can travel back in time, collaborate, and experiment in parallel. Git is the most popular distributed version control system today.

Centralized vs Distributed

Centralized (SVN) Central server A B C Distributed (Git) Remote FullRepo A FullRepo B FullRepo C Every developer has a full local copy commit, inspect history and branch offline
Centralized depends on a central server; in distributed, everyone has a full repository and the remote is only for collaboration sync

Installation & first-time config

After installing Git, the first thing is to set your identity — it is recorded with every commit:

  git config --global user.name  "Your Name"
git config --global user.email "you@example.com"
git config --global init.defaultBranch main
  

--global sets config for all your repositories, once only. Use --local (the default) for project-level config that applies only to the current repository.

?Knowledge check
1What type of version control system is Git?
Centralized
Distributed
Local-only
Cloud-based
2What does `git config --global user.name "Name"` do?
Create a new repository
Set the global committer username
Create a new branch
Set a remote URL
3Which of the following is NOT a core Git advantage?
Works offline
Cheap branch creation
Must stay online to commit
Full history kept locally

Day 2Local repo essentials

The local repository is the foundation of Git. Today you'll create a repository, track files and commit changes — Git's most core workflow.

Create a repository

  mkdir my-project && cd my-project
git init
  

git init creates a hidden .git folder in the current directory — the heart of the repository, storing all version data. From then on this directory is a Git repository.

Track & commit

Working tree Working Directory files you are editing git add stage Index Staging Area snapshot ready to commit git commit commit Repository Repository permanent history
The core Git workflow: working tree → git add → index → git commit → repository
  touch README.md                     # create a file
git add README.md                    # stage the file
git commit -m "Add README"          # commit to the repository
git status                           # show current status
git log --oneline                    # show commit history
  

git add takes a snapshot — putting the current state of files into the index. git commit is stamp-and-archive — writing the staged snapshot permanently into the repository. Separating the two steps lets you precisely control what each commit contains.

Hands-on: your first commit

Run these commands in the terminal below (click a command to send it to the terminal):

  1. git init — initialize the repository
  2. touch hello.txt — create a file
  3. git status — check status (hello.txt is Untracked)
  4. git add hello.txt — stage the file
  5. git status — check again (now staged)
  6. git commit -m "Add hello.txt" — commit
  7. git log --oneline — view history
?Knowledge check
1What does `git add` do?
Commit files to the repository
Add files from the working tree to the index
Push code to a remote
Create a new branch
2What does the `-m` flag do in `git commit -m "msg"`?
Amend the previous commit
Set the author of the commit message
Provide the message directly on the command line
Squash multiple commits
3Which command shows the commit history?
git history
git log
git show
git list
4What is the purpose of the `.git` directory?
Store project source code
Store Git core data (the version database)
Store build output
Store dependencies

Day 3Three areas & diff

Understand the three areas — working tree, index, repository — and learn to inspect differences with git diff. This is the key to leveling up in Git.

The file lifecycle

Untracked Staged Committed Modified git add git commit edit file git add after edit
Files cycle through Untracked → Staged → Committed → Modified → Staged

Three uses of git diff

  git diff              # working tree vs index (unstaged changes)
git diff --staged     # index vs HEAD (staged, not yet committed)
git diff HEAD         # working tree vs HEAD (all uncommitted changes)
  

git diff output format: @@ -oldLine,count +newLine,count @@ marks the diff position; green + is added lines, red - is removed lines.

Hands-on: observe the diff

Finish the Day 2 exercise first, then continue:

  1. echo "Hello Git" > hello.txt — modify the file content
  2. git diff — view working-tree changes
  3. git add hello.txt — stage
  4. git diff --staged — view staged changes
  5. echo "Line 2" >> hello.txt — modify again
  6. git status — note: staged and unstaged changes at once
  7. git add hello.txt — restage the latest content
  8. git commit -m "Update hello.txt" — commit
?Knowledge check
1What does `git diff` (no args) compare?
working tree vs repository
index vs repository
working tree vs index
between two branches
2Which command takes files from the index into the repository?
git add
git commit
git push
git save
3Why does Git have a staging area (instead of committing directly)?
To slow down commits
To let you precisely choose what each commit contains
To use more disk space
To prevent file loss
4What does `git diff --staged` show?
working tree vs index
index vs repository
between two commits
remote vs local

Day 4Branching

Branching is Git's most powerful feature — it lets you develop multiple features in parallel without interference. Mastery of branches is the foundation of team collaboration.

What is a branch

A branch is essentially a movable pointer to a commit. Creating one costs almost nothing — it only creates a new pointer, no files are copied.

Create a branch and commit C1 C2 C3 C4 main → fork point main feature git checkout -b feature → new commit C4
Create feature from C3; feature gains C4 while main still points to C3

Core commands

  git branch                    # list all branches
git branch feature            # create a branch (no switch)
git switch feature            # switch to a branch (recommended)
git checkout feature          # switch to a branch (old syntax)
git switch -c feature         # create and switch (recommended)
git checkout -b feature       # create and switch (old syntax)
git merge feature             # merge feature into the current branch
git branch -d feature         # delete a merged branch
  

Merging: fast-forward vs three-way

Fast-forward C1 C2 C3 main→ main is at C2 before merge feature C1 C2 C3 main + feature → pointer moves up, no new commit Three-way merge C2 C3 C4 main→ feature→ C3 C4 M main → merge commit M each branch has new commits a merge commit with two parents
Fast-forward: moves the pointer; three-way merge: creates a new commit joining two branch lines

Merge conflict: when two branches modify the same region of the same file, Git cannot merge automatically and reports a conflict. You must edit the files to resolve it (keep what you need), then git add + git commit.

Hands-on: branch operations
  1. git branch — view the current branch
  2. git branch feature — create a branch
  3. git switch feature — switch to feature
  4. touch feature.txt — create a new file
  5. git add feature.txt — stage
  6. git commit -m "Add feature.txt" — commit
  7. git switch main — switch back to main
  8. git merge feature — merge
  9. git log --oneline — view history
?Knowledge check
1Which command creates a new branch WITHOUT switching to it?
git switch -c feature
git branch feature
git checkout feature
git merge feature
2What is a "fast-forward" merge?
A merge that is very quick
The current branch has no new commits, so the pointer simply moves to the target branch
A merge with conflicts to fix quickly
The two branches are identical
3When a merge conflict happens, what should you do?
Delete the conflicting files
Manually edit the conflicted files, keep the correct content, then add + commit
Abort and run git reset --hard
Re-clone the repository
4What is the relationship between `git switch` and `git checkout`?
Completely different commands
switch is a focused part of checkout, used only for switching branches
checkout is an alias of switch
No relationship

Day 5Remotes & collaboration

Remote repositories let you share code with your team. Learn clone, push, pull, fetch, and master the GitHub collaboration workflow.

Local vs remote

Local repo working tree + index + repository + local branches Remote repo GitHub / GitLab / Gitee remote branches + team code git push push local commits git pull / fetch pull remote updates
push sends local changes to the remote; pull/fetch brings remote updates back to local

Core commands

  git clone <url>                    # clone a remote repo locally
git remote add origin <url>        # link a remote repository
git remote -v                       # show remote repositories
git push origin main                # push local branch to remote
git push -u origin main             # first push, set upstream
git pull origin main                # pull and merge (= fetch + merge)
git fetch origin                    # fetch only, no auto-merge
git push                            # short form once tracking is set
  

fetch vs pull: git fetch only downloads remote updates without modifying your local branches — safe and controllable; git pull = fetch + merge, integrating straight into the current branch. Beginners are advised to use fetch + manual merge for more control.

GitHub collaboration workflow

  1. Fork — Fork the project to your own account on GitHub
  2. Clonegit clone your fork locally
  3. Branchgit switch -c fix-bug create a feature branch
  4. Commit — modify code, git add + git commit
  5. Pushgit push origin fix-bug to your fork
  6. PR — open a Pull Request on GitHub to request a merge
  7. Review & Merge — merge after the code review passes
Hands-on: remote operations

This terminal simulates a remote repository, so you can practice push and pull:

  1. git remote add origin https://github.com/me/repo.git — add a remote
  2. git remote -v — view remotes
  3. git push -u origin main — push and set tracking
  4. git pull origin main — pull (simulated)
  5. git fetch origin — fetch only
?Knowledge check
1What does `git clone` do?
Push local code to a remote
Clone a remote repository to your local machine
Create a local repository copy
Delete a remote repository
2What is the difference between `git fetch` and `git pull`?
No difference
fetch only downloads, pull = fetch + merge
fetch pushes, pull pulls
pull only downloads without merging
3What does `-u` mean in `git push -u origin main`?
Force push
Set the upstream tracking branch, then git push works directly
Push all branches
Undo the push
4What is the prerequisite for opening a Pull Request on GitHub?
You must be the repo owner
You have pushed a branch to a remote (usually your forked repository)
The repo must be public
You must have write access

Day 6Undo & revert

Everyone makes mistakes — Git offers several ways to undo. The key is understanding what each command undoes and how far it reaches.

Three undo scenarios

Comparing the three git reset modes Repository (HEAD) — index — working tree --soft only moves HEAD --mixed (default) HEAD + index --hard all areas (dangerous!) ■ affected □ kept git revert <commit> creates a new "inverse" commit ✓ safe, no history rewrite, good for shared git checkout -- <file> discard unstaged working changes ⚠ irreversible! restores to index state
reset moves the pointer (rewrites history); revert creates an inverse commit (keeps history)

git stash: temporary storage

When you are mid-way through work on branch A and need to switch to branch B to fix a bug, but A's changes aren't ready to commit — git stash "hides" the working-tree changes and restores a clean tree. After the bug fix, git stash pop retrieves them.

  git stash               # stash current working-tree changes
git stash list          # list stashes
git stash pop           # restore the latest stash (and drop it)
git stash apply         # restore without dropping (can target stash@{1})
git stash drop          # delete a specific stash
  

git reset --hard and git checkout -- <file> permanently discard uncommitted changes and cannot be recovered! Confirm carefully before use. If something was deleted by mistake, git reflog may help you find it (committed ones only).

Hands-on: undo operations
  1. echo "wrong" > hello.txt — modify a file
  2. git checkout -- hello.txt — discard working changes
  3. echo "staged" > temp.txt — create a new file
  4. git add temp.txt — stage
  5. git reset HEAD temp.txt — unstage
  6. echo "wip" > work.txt — create a work file
  7. git add work.txt — stage
  8. git stash — stash the work
  9. git stash pop — restore
  10. git log --oneline — view history
?Knowledge check
1What does `git reset --hard` do?
Only moves the HEAD pointer
Moves HEAD and resets the index
Hard revert: moves HEAD + resets index + discards working-tree changes
Undo the last commit but keep changes
2What is the core difference between `git revert` and `git reset`?
No difference
revert creates a new commit to undo; reset moves the pointer and rewrites history
revert is faster
reset is safer
3What does `git stash` do?
Delete files
Temporarily save working-tree changes and restore a clean tree
Permanently store files
Create a backup branch
4What is the effect of `git checkout -- <file>`?
Stage the file
Commit the file
Restore the file to the index/HEAD state, discarding working changes
Delete the file

Day 7Advanced & best practices

On the last day you'll learn rebase, tag, .gitignore and commit conventions — skills that take you from "using Git" to "using Git well".

git rebase

rebase replays your branch's commits on top of the latest commits of another branch, keeping a linear history. How it differs from merge:

merge (keeps branch history) C1 C2 C4 C3 M merge commit M, history forks rebase (linear history) C1 C2 C4 C3 C3' C5' C3 replayed after C4, becomes C3' linear history, no merge commit ⚠ rewrites history, don't use on shared branches
merge keeps the full branch history; rebase rewrites commits to be linear

git tag: release markers

  git tag v1.0.0                  # lightweight tag
git tag -a v1.0.0 -m "Release"  # annotated tag (recommended)
git tag                         # list all tags
git push origin v1.0.0          # push a single tag
git push --tags                 # push all tags
  

.gitignore: ignoring files

Build output, dependencies, IDE config and so on should not be under version control. Create a .gitignore file to specify ignore rules:

  # dependencies
node_modules/
vendor/

# build output
dist/
build/
*.o
*.class

# IDE
.idea/
.vscode/
*.swp

# system files
.DS_Store
Thumbs.db

# environment variables
.env
.env.local
  

Commit message conventions (Conventional Commits): type(scope): description, e.g. feat(auth): add login page, fix(api): handle null response, docs: update README. Types include feat / fix / docs / style / refactor / test / chore.

Hands-on: advanced operations
  1. git tag -a v1.0 -m "First release" — create a tag
  2. git tag — list tags
  3. touch .gitignore — create an ignore file
  4. echo "node_modules/" > .gitignore — write a rule
  5. git add .gitignore — stage
  6. git commit -m "chore: add .gitignore" — commit
  7. git log --oneline — view the full history
?Knowledge check
1What does `git rebase` do?
Merge branches
Replay the current branch's commits on top of the target branch, keeping a linear history
Delete commits
Create tags
2What is the purpose of a `.gitignore` file?
Store Git config
Specify files and directories Git should not track
Store passwords
Record commit logs
3In Conventional Commits, what does "feat(auth): add login" mean?
Fixed a login bug in auth
Added a login feature in the auth module
Updated auth documentation
Refactored the auth login
4What kind of tag does `git tag -a v1.0 -m "Release"` create?
Lightweight tag
Annotated tag
Remote tag
Temporary tag

📋 Command cheat sheet

The most common Git commands for daily development, grouped by category. Type a keyword to filter.

Configuration

git config --global user.name "Name"
Set the global username
git config --global user.email "Email"
Set the global email
git config --list
Show all config
git config --global init.defaultBranch main
Set the default branch name

Create repository

git init
Initialize a Git repository in the current directory
git clone <url>
Clone a remote repository locally
git clone <url> <dir>
Clone into a specific directory

Basic operations

git add <file>
Stage a file
git add .
Stage all changes
git commit -m "msg"
Commit the index to the repository
git commit -am "msg"
add + commit (tracked files only)
git status
Show working-tree status
git status -s
Compact status
git log
Show commit history
git log --oneline --graph
Graphical compact history
git diff
Show working tree vs index differences
git diff --staged
Show index vs repository differences
git show <hash>
Show details of a commit

Branching

git branch
List all local branches
git branch <name>
Create a new branch
git branch -a
List all branches (including remote)
git branch -d <name>
Delete a merged branch
git switch <name>
Switch branches
git switch -c <name>
Create and switch branch
git checkout <name>
Switch branch (old syntax)
git checkout -b <name>
Create and switch (old syntax)
git merge <name>
Merge the named branch into the current branch

Remotes

git remote -v
Show remote repositories
git remote add <name> <url>
Add a remote repository
git remote remove <name>
Remove a remote repository
git fetch <remote>
Fetch remote updates (no merge)
git pull <remote> <branch>
Fetch and merge
git push <remote> <branch>
Push a local branch to the remote
git push -u origin main
First push and set tracking

Undo

git checkout -- <file>
Discard working-tree changes
git reset HEAD <file>
Unstage (keep changes)
git reset --soft HEAD~1
Undo last commit, keep changes staged
git reset --mixed HEAD~1
Undo commit and staging, keep working tree
git reset --hard HEAD~1
Undo completely (dangerous — discards all changes)
git revert <hash>
Create an inverse commit (safe)
git stash
Temporarily save working changes
git stash list
List stash entries
git stash pop
Restore the latest stash
git clean -fd
Delete untracked files and directories

Tags

git tag
List all tags
git tag <name>
Create a lightweight tag
git tag -a <name> -m "msg"
Create an annotated tag (recommended)
git push origin <tag>
Push a single tag
git push --tags
Push all tags

Advanced

git rebase <branch>
Rebase the current branch onto the target
git rebase -i HEAD~3
Interactive rebase of the last 3 commits
git cherry-pick <hash>
Apply a specific commit to the current branch
git reflog
Show HEAD movement history (recover lost commits)
git bisect
Binary-search the commit that introduced a bug
git blame <file>
Show who last modified each line
🎓

Congratulations!

Git Quick Start · 7-Day Interactive
0/21
Quiz total score

You've mastered the core concepts and operations of Git. Keep gaining experience in practice and explore more advanced features!

⚡ Git terminal simulator