Files
DailyChallenge_ProgrammingD…/Day_0/README.md
T

70 lines
3.8 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# Day_0 · 注册 GitHub,把 Hello World 推送到自己的仓库(第零节)
> 预计耗时:25~30 分钟
> 今天做四件事:**注册 GitHub、建自己的仓库、用命令行把代码推上去、在工单里交仓库地址**。
> 推送的目标是你**自己的 GitHub 仓库**,不是工作室的仓库(工作室仓库只有学长能 push)。
## 今日知识点
Git 是**代码版本管理工具**,GitHub 是存放代码的网站。今天掌握这些命令:
| 命令 | 作用 |
| --- | --- |
| `git init` | 把当前文件夹变成 Git 仓库 |
| `git status` | 查看当前状态(改了哪些文件) |
| `git add hello.py` | 把文件"登记"进暂存区(`git add .` 表示全部) |
| `git commit -m "说明"` | 把暂存区内容存成本地记录 |
| `git branch -M main` | 把默认分支命名为 `main` |
| `git remote add origin <仓库地址>` | 关联远程仓库(`origin` 是它的名字) |
| `git push -u origin main` | 首次推送到远程(`-u` 记住关联,之后直接 `git push`) |
## 先学(教程)
- 廖雪峰 Git 教程(重点看"远程仓库"和"添加远程库",我们和教程做一模一样的事):https://liaoxuefeng.com/books/git/remote/
- GitHub 官方文档·推送提交到远程仓库:https://docs.github.com/zh/get-started/using-git/pushing-commits-to-a-remote-repository
- 菜鸟教程 Git 基础:https://www.runoob.com/git/git-tutorial.html
- **GitHub 稳定访问方法**(国内打不开 GitHub / 推送超时 / 网页访问失败时,按这篇操作):https://zhuanlan.zhihu.com/p/1946180155610469521
## 任务(后做)
1. **注册 GitHub 账号**:打开 https://github.com → Sign up,用真实信息注册(免费),记住你的**用户名**
2. **创建个人仓库**:右上角 `+` → New repository → 仓库名填 `hello-daily-challenge`
→ 选 Public → 点 Create repository(**不要在页面上勾选任何初始化选项**,保持空仓库)
3. 在电脑上新建文件夹 `hello-daily-challenge`,在里面新建 `hello.py`,
文件内容**直接写**(一个字符都不要错):
```python
print("Hello World")
```
4. 在该文件夹里打开命令行,依次执行:
```
git init
git add .
git commit -m "add hello world"
git branch -M main
git remote add origin https://github.com/你的用户名/hello-daily-challenge.git
git push -u origin main
```
> `git remote add` 那行,把"你的用户名"换成你注册时用的用户名。
5. 推送时命令行会问用户名和密码,这样填:
- 用户名:你的 GitHub 用户名
- 密码:**不是登录密码**,而是 Personal Access Token(怎么生成看第 6 步)
6. **生成 Token(密钥)**:GitHub 网页 → 点头像 → Settings → 拉到最下面
Developer settings → Personal access tokens → Tokens (classic) → Generate new token (classic)
→ 勾选 `repo` 权限 → Generate → **复制那串 token**(只显示一次)
7. 刷新 https://github.com/你的用户名/hello-daily-challenge ,确认 `hello.py` 出现了
8. 运行验证:命令行 `python hello.py`,看到输出 `Hello World`
> 卡壳求助:任何一步报错,把**完整报错文字**贴在 Day_0 工单里,学长会帮你。
> 常见坑:用户名拼错、token 没勾 repo 权限、文件夹没先 `git init`。
> GitHub 打不开/推送超时:先看上面"GitHub 稳定访问方法"那篇教程,多半是网络问题,不是你的操作问题。
## 完成标准
- [ ] GitHub 账号已注册
- [ ] 个人仓库 `hello-daily-challenge` 里有 `hello.py`
- [ ] `python hello.py` 输出 `Hello World`
- [ ] 能说出来:add / commit / push 分别做了什么
**提交方式**:在 **Day_0 工单**下方"撰写"处,贴上你的 **GitHub 仓库地址**
(形如 `https://github.com/你的用户名/hello-daily-challenge`),然后点击"评论"。