What is GitHub? — GitHub 是什么?
🇨🇳 中文
GitHub 是程序员的
为什么要学?三个理由:
- 📚 学习 — 看真正的程序员怎么写代码
- 👥 合作 — 多人一起做项目不会互相覆盖
- 💼 简历 — 找工作时面试官会先看你的 GitHub
🇬🇧 English
GitHub is the
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.
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 / 不需要联网
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")
🇨🇳 中文
仓库(
每个 repo 都是普通的文件夹 + 一个隐藏的 .git/ 子文件夹(那里就是 Git 的"魔法"):
🇬🇧 English
A repository (
Every repo is just a normal folder + a hidden .git/ subfolder (that's where Git's magic lives):
📁 .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
被 Git 跟踪的项目文件夹 — 代码加历史。
别人最先看到的文件。说明项目是干什么的。
列出 Git 不要跟踪的文件 — 密码、大文件等。
收藏喜欢的仓库 — 像"加心"。
把别人的仓库拷一份到你账号下。
把 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.
👆 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).
4. Branches — 分支 (Click buttons to animate / 点按钮看动画)
🇨🇳 中文
分支(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:
Click a button above to step through. / 点按钮一步步看。
git branch列出仓库里所有的分支。
git checkout -b feat/xfeat/x AND switch to it.新建一个分支并切换过去。
git switch main切换到已有的分支(新版命令)。
git merge feat/xfeat/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.
💡 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.
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 给主页加了登录表单。用户可以输入邮箱和密码,提交前会验证邮箱格式。
报 bug、提建议、问问题 — 公开的待办列表。
合并前队友看你的代码,提建议。
两人改了同一行 — Git 让你挑保留哪个。
每次 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.
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
Step 3: Tell Git who you are — 告诉 Git 你是谁
Step 4: Make your first repo — 第一个仓库
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 — 小测验
git commit do?git commit 做什么?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。main version. When you're done, merge it back. / 分支让你在不影响主线的情况下试新东西。.gitignore do?.gitignore 是干什么的?.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。整个开源世界都在等你。