GitHub

The world's largest platform for sharing & collaborating on code

全世界最大的代码共享和协作平台 — 高中信息课入门

What is GitHub? — GitHub 是什么?

🇨🇳 中文

GitHub 是程序员的social network,也是全世界最大的代码repository托管平台。每天有几亿个项目在上面 — 从课堂作业到 Linux 系统的源代码、Facebook 的 React 框架,全都在 GitHub 上。

为什么要学?三个理由:

  • 📚 学习 — 看真正的程序员怎么写代码
  • 👥 合作 — 多人一起做项目不会互相覆盖
  • 💼 简历 — 找工作时面试官会先看你的 GitHub

🇬🇧 English

GitHub is the social network for programmers, and the world's largest hosting platform for code repositories. Hundreds of millions of projects live there — from school homework to the Linux source code and Facebook's React framework.

Why learn it? Three reasons:

  • 📚 Learn — Read code from real-world programmers
  • 👥 Collaborate — Work with others without overwriting each other
  • 💼 Portfolio — Recruiters look at your GitHub before they call you

1. Git vs GitHub — 两个不一样的东西

🇨🇳 中文

这两个名字很像 — 但不是同一个东西。新手最容易混。

🇬🇧 English

The two names look alike — but they're not the same thing. This is the #1 confusion for beginners.

🔧 Git

A tool on your computer. Tracks changes to your files. Works offline. Free, open source.
电脑上的工具。记录文件的每次修改。可以离线用。免费开源。

  • Created in 2005 by Linus Torvalds (Linux creator) / 2005 年 Linux 发明者 Linus 写的
  • Lives on your computer / 装在你电脑上
  • Used through the terminal / 用终端命令操作
  • Doesn't need internet / 不需要联网
🐙 GitHub

A website. Hosts your Git repos online so you can share, collaborate, and back them up.
一个网站。把你的 Git 仓库放到云上 — 分享、协作、备份。

  • Founded in 2008, owned by Microsoft since 2018 / 2008 年成立,2018 微软收购
  • Lives on the internet / 在云上
  • Used through a browser (or terminal) / 用浏览器或终端
  • Adds: pull requests, issues, actions, social features / 加了 PR、Issues、Actions、社交功能

💡 Simple analogy — 一个比喻

中文: Git 就像 Microsoft Word 的"修订记录"功能,但更强 — 在你的电脑上。GitHub 就像 Google Drive — 把文档放到云上,让别人能看能改。两个一起用最强。

English: Git is like Word's "Track Changes" on steroids — runs on your computer. GitHub is like Google Drive — puts your files in the cloud so others can see and edit. Use them together for the full power.

2. The Repository — 仓库("Repo")

🇨🇳 中文

仓库repository,简称 repo)就是一个项目的 — 所有代码、图片、文档、和每一次修改的历史记录都装在里面。

每个 repo 都是普通的文件夹 + 一个隐藏的 .git/ 子文件夹(那里就是 Git 的"魔法"):

🇬🇧 English

A repository (repo for short) is the home of a project — all code, images, docs, and the complete history of every change ever made live inside.

Every repo is just a normal folder + a hidden .git/ subfolder (that's where Git's magic lives):

📁 my-website/ # <-- 这就是一个 repo / This is a repo
📁 .git/ # 隐藏的 Git 数据库(别动)/ hidden Git database (don't touch)
📄 HEAD
📄 config
📁 objects/ # 每次提交的快照 / snapshots of every commit
📁 refs/ # 分支指针 / branch pointers
📄 index.html # 你的代码 / your code
📄 style.css
📄 app.js
📄 README.md # 项目介绍 / project description
📄 .gitignore # 不想跟踪的文件 / files to ignore
Repository
仓库
A project folder tracked by Git — code + history.
被 Git 跟踪的项目文件夹 — 代码加历史。
README.md
说明文档
First file people see. Says what the project is.
别人最先看到的文件。说明项目是干什么的。
.gitignore
忽略列表
List of files Git should ignore (passwords, big files, etc.).
列出 Git 不要跟踪的文件 — 密码、大文件等。
Star
收藏
Bookmark a repo you like. Like a "favorite".
收藏喜欢的仓库 — 像"加心"。
Fork 🍴
复刻(拷一份)
Make your own copy of someone else's repo on GitHub.
把别人的仓库拷一份到你账号下。
Clone 📥
克隆(下载)
Download a repo from GitHub to your computer.
把 GitHub 上的仓库下载到电脑上。

3. Commits — 提交记录 (Click any commit / 点任意一行)

🇨🇳 中文

每次你"提交"(commit),Git 都会拍一张当前所有文件的快照,加上一个独一无二的 ID 和你写的说明。这就成了项目历史的一个"存档点"。出问题了?回到任何一个旧 commit 就行。

🇬🇧 English

Every time you "commit", Git takes a snapshot of all your files plus a unique ID and your message. Each commit becomes a permanent save point in the project's history. Something broke? Roll back to any old commit.

3a8f2c1Initial commit
Alice · 5d ago
b41e7d2Add homepage with heading
Alice · 4d ago
c92d108Style: add CSS for homepage
Alice · 3d ago
d05a3f9branch: contact-formAdd contact form HTML
Bob · 2d ago
e7c8b41Validate email field
Bob · 2d ago
f1d9e0aMERGEMerge pull request #1: contact form
Alice · 1d ago
a3b1c5eFix: typo in welcome message
Alice · 6h ago

👆 Click a commit above to see what it did. / 点上面的任意一行看说明。

💡 Good commit messages — 好的提交消息

中文: 写得好的 commit 消息应该用一句话告诉别人这次提交干了什么。前缀用动词(Add、Fix、Update、Remove)。

English: A good commit message tells someone in one short line what the commit did. Start with a verb (Add, Fix, Update, Remove).

✅ Add login button to homepage
✅ Fix typo in About page
❌ stuff
❌ asdfasdf
❌ final final FINAL v2 (real)

4. Branches — 分支 (Click buttons to animate / 点按钮看动画)

🇨🇳 中文

分支branch)让你可以试新东西不影响主线。每个仓库都有一个 main(或 master)主分支 — 它是"稳定版"。要加新功能?开个新分支:

🇬🇧 English

A branch lets you try new things without breaking the main project. Every repo has a main (or master) branch — this is the "stable version". Want to add a feature? Create a branch:

main feature/login c1 c2 c3

Click a button above to step through. / 点按钮一步步看。

git branch
看分支
List all branches in this repo.
列出仓库里所有的分支。
git checkout -b feat/x
开新分支
Create a new branch called feat/x AND switch to it.
新建一个分支并切换过去。
git switch main
切回主分支
Switch to an existing branch (newer way to say checkout).
切换到已有的分支(新版命令)。
git merge feat/x
合并分支
Combine the changes from feat/x into the current branch.
把 feat/x 的改动合并到当前分支。

⚠️ Project Rule — 项目规矩

中文: 在团队里,几乎从来不直接往 main 提交!永远开新分支 → 写代码 → 提 Pull Request → 别人审核通过后再合并。这样可以避免破坏正在用的版本。

English: On a team, you almost never commit straight to main! Always create a branch → write code → open a Pull Request → wait for review → then merge. This protects the working version from broken code.

5. The Daily Workflow — 每天的工作流

🇨🇳 中文

每个程序员每天都重复这 5 步。学会这个循环,你就能上手任何项目

🇬🇧 English

Every programmer repeats these 5 steps every day. Master this cycle and you can jump into any project.

1
Pull
Get the latest code
git pull
拉最新代码
2
Edit
Make your changes
(edit files)
改代码
3
Add
Stage what you changed
git add .
把改动加入暂存区
4
Commit
Save a snapshot
git commit -m "..."
保存一个快照
5
Push
Send to GitHub
git push
推送到 GitHub

💡 Three areas Git tracks — Git 管的三个地方

1. Working Directory — your real files / 工作目录 — 你看到的真实文件
2. Staging Area (after git add) — files ready to be committed / 暂存区 — 准备好要提交的文件
3. Repository (after git commit) — saved history / 仓库 — 已经保存的历史

6. Pull Requests — 合并请求 (Try the buttons / 点按钮)

🇨🇳 中文

Pull Request(PR,合并请求)是 GitHub 最重要的功能。它说:"我做了一些改动,你看看,没问题就把它合并进 main 吧。"别人可以评论、提建议、让你改,确认 OK 再合并。

🇬🇧 English

A Pull Request (PR) is GitHub's most important feature. It says: "I made some changes — please review them, and if they look good, merge them into main." People can comment, suggest fixes, ask for changes — and approve when ready.

✓ Pull request successfully merged and closed / 合并请求已成功合并并关闭
Add login form to homepage #42
● Open opened by @xiaoming · 2 hours ago
feature/loginmain

Description / 描述

This PR adds a login form to the homepage. Users can now type their email and password. Validates that the email looks valid before submit. / 这个 PR 给主页加了登录表单。用户可以输入邮箱和密码,提交前会验证邮箱格式。

3 files changed · +87 -3
📄 index.html +24 -1
📄 style.css +38 -0
📄 login.js +25 -2
Issues
议题
Bug reports, feature requests, questions. Like a public to-do list.
报 bug、提建议、问问题 — 公开的待办列表。
Code Review
代码审查
Teammates read your PR and suggest improvements before merge.
合并前队友看你的代码,提建议。
Conflict
冲突
When two people change the same line. Git asks you to choose which one to keep.
两人改了同一行 — Git 让你挑保留哪个。
CI / Actions
自动化测试
GitHub auto-runs your tests on every PR. Green check = good!
每次 PR GitHub 自动跑测试。绿勾 = 通过!

7. Try It in Terminal — 在终端里实战

🇨🇳 中文

下面是一个真的可以用的模拟终端。试试 git 命令 — 创建仓库、提交、看历史、查状态,都能用。

🇬🇧 English

Below is a working simulated terminal. Try real git commands — create a repo, commit changes, view history, check status. They all work here.

student@github — bash — 80×24
Welcome to the GitHub terminal simulator!
欢迎使用 GitHub 终端模拟器
Type help for available commands. / 输入 help 看可用命令

8. Account Setup — 怎么开始用

🇨🇳 中文

三步开始你自己的 GitHub 之旅。完全免费

🇬🇧 English

Three steps to start your GitHub journey. Completely free.

Step 1: Create an account — 注册账号

Go to github.com/signup and pick a username (this becomes your URL: github.com/yourname) plus a real email.
打开 github.com/signup,选用户名(会成为你的网址)和填一个真实邮箱。

Step 2: Install Git — 装 Git

# macOS (with Homebrew) brew install git # Windows # Download from https://git-scm.com # Linux (Debian/Ubuntu) sudo apt install git # Check it worked / 检查装好没 git --version

Step 3: Tell Git who you are — 告诉 Git 你是谁

# Once on every computer / 每台电脑只设一次 git config --global user.name "Your Name" git config --global user.email "you@example.com" # Use the same email as your GitHub account! / 邮箱要和 GitHub 账号一样!

Step 4: Make your first repo — 第一个仓库

# 1. Create a folder / 新建文件夹 mkdir my-first-repo cd my-first-repo # 2. Initialize Git / 初始化 Git git init # 3. Create a README / 写个说明文件 echo "# My First Repo" > README.md # 4. Stage and commit / 暂存并提交 git add . git commit -m "Initial commit" # 5. Push to GitHub (after creating an empty repo on github.com) git remote add origin https://github.com/yourname/my-first-repo.git git branch -M main git push -u origin main

You've shipped code to the world. — 你的代码上线了。

Anyone with the URL can now see your project. Welcome to the open-source world.

现在任何人通过那个网址都能看到你的项目。欢迎加入开源世界。

9. Quick Quiz — 小测验

0 / 6 correct
1. What's the difference between Git and GitHub?
Git 和 GitHub 有什么区别?
They're exactly the same thing
Git is a tool on your computer; GitHub is a website that hosts Git repos
Git is for code; GitHub is for documents
GitHub is offline; Git is online
✅ Git is a tool on your computer that tracks changes. GitHub is a website that hosts Git repos online so you can share and collaborate. / Git 是电脑上的工具,GitHub 是网站。
2. What does git commit do?
git commit 做什么?
Sends your code to GitHub
Saves a snapshot of your staged changes locally
Deletes your code permanently
Creates a new branch
git commit saves a snapshot of your staged changes to your local repo history. To send it to GitHub, you also need git push. / commit 是本地保存快照,push 才上传到 GitHub。
3. Why use branches?
为什么要用分支?
Branches make Git run faster
Branches let you skip writing tests
To work on features without breaking the main version
Branches save disk space
✅ Branches let you experiment with new features without breaking the working main version. When you're done, merge it back. / 分支让你在不影响主线的情况下试新东西。
4. What's a Pull Request (PR)?
什么是 Pull Request (PR)?
A way to delete a repository
A request to download files
A request to merge your branch into main, where teammates can review first
A way to ask for help from GitHub support
✅ A Pull Request proposes merging your branch into main. Teammates review the changes, comment, ask for fixes, then approve & merge. / PR 提议把分支合并到 main,队友审核后再合并。
5. What's in the order of the daily workflow?
每天的工作流顺序是什么?
commit → add → push → pull → edit
pull → edit → add → commit → push
push → pull → commit → add → edit
edit → push → pull → add → commit
✅ The order is: pull (get latest) → edit (make changes) → add (stage) → commit (snapshot) → push (upload). / 拉、改、暂存、提交、推送。
6. What does .gitignore do?
.gitignore 是干什么的?
It blocks people from cloning your repo
It lists files Git should NOT track (passwords, big files, etc.)
It deletes old commits
It encrypts your code
.gitignore tells Git which files to ignore — passwords, build outputs, big media files, OS junk. Crucial for keeping secrets out of GitHub! / 列出不要跟踪的文件 — 防止密码上传到 GitHub。

Welcome to GitHub 🐙 — 欢迎来到 GitHub

Now go to github.com, create a real account, and push your first commit. The whole open-source world is waiting.

现在打开 github.com 注册一个真账号,推送你的第一个 commit。整个开源世界都在等你。

GitHub — 程序员的协作平台 | A High School IT Lesson

Made for Chinese English learners — 为学习英语的中国朋友制作