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.
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
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.
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
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.
Run these commands in the terminal below (click a command to send it to the terminal):
-
git init— initialize the repository -
touch hello.txt— create a file -
git status— check status (hello.txt is Untracked) -
git add hello.txt— stage the file -
git status— check again (now staged) -
git commit -m "Add hello.txt"— commit -
git log --oneline— view history
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
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.
Finish the Day 2 exercise first, then continue:
-
echo "Hello Git" > hello.txt— modify the file content -
git diff— view working-tree changes -
git add hello.txt— stage -
git diff --staged— view staged changes -
echo "Line 2" >> hello.txt— modify again -
git status— note: staged and unstaged changes at once -
git add hello.txt— restage the latest content -
git commit -m "Update hello.txt"— commit
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.
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
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.
-
git branch— view the current branch -
git branch feature— create a branch -
git switch feature— switch to feature -
touch feature.txt— create a new file -
git add feature.txt— stage -
git commit -m "Add feature.txt"— commit -
git switch main— switch back to main -
git merge feature— merge -
git log --oneline— view history
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
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
- Fork — Fork the project to your own account on GitHub
- Clone —
git cloneyour fork locally - Branch —
git switch -c fix-bugcreate a feature branch - Commit — modify code,
git add+git commit - Push —
git push origin fix-bugto your fork - PR — open a Pull Request on GitHub to request a merge
- Review & Merge — merge after the code review passes
This terminal simulates a remote repository, so you can practice push and pull:
-
git remote add origin https://github.com/me/repo.git— add a remote -
git remote -v— view remotes -
git push -u origin main— push and set tracking -
git pull origin main— pull (simulated) -
git fetch origin— fetch only
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
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).
-
echo "wrong" > hello.txt— modify a file -
git checkout -- hello.txt— discard working changes -
echo "staged" > temp.txt— create a new file -
git add temp.txt— stage -
git reset HEAD temp.txt— unstage -
echo "wip" > work.txt— create a work file -
git add work.txt— stage -
git stash— stash the work -
git stash pop— restore -
git log --oneline— view history
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:
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.
-
git tag -a v1.0 -m "First release"— create a tag -
git tag— list tags -
touch .gitignore— create an ignore file -
echo "node_modules/" > .gitignore— write a rule -
git add .gitignore— stage -
git commit -m "chore: add .gitignore"— commit -
git log --oneline— view the full history
📋 Command cheat sheet
The most common Git commands for daily development, grouped by category. Type a keyword to filter.
Configuration
Create repository
Basic operations
Branching
Remotes
Undo
Tags
Advanced
Congratulations!
You've mastered the core concepts and operations of Git. Keep gaining experience in practice and explore more advanced features!