Update Day_0: 改为注册GitHub并推送到个人仓库, 工单交仓库地址
This commit is contained in:
+45
-33
@@ -1,55 +1,67 @@
|
|||||||
# Day_0 · Git 入门与 Hello World(第零节)
|
# Day_0 · 注册 GitHub,把 Hello World 推送到自己的仓库(第零节)
|
||||||
|
|
||||||
> 预计耗时:20~30 分钟
|
> 预计耗时:25~30 分钟
|
||||||
> 这一节不写任何难代码,只做三件事:**会用 Git、会克隆仓库、会提交作业**。
|
> 今天做四件事:**注册 GitHub、建自己的仓库、用命令行把代码推上去、在工单里交仓库地址**。
|
||||||
|
> 推送的目标是你**自己的 GitHub 仓库**,不是工作室的仓库(工作室仓库只有学长能 push)。
|
||||||
|
|
||||||
## 今日知识点
|
## 今日知识点
|
||||||
|
|
||||||
Git 是一个**代码版本管理工具**。今天只需要掌握四个动作:
|
Git 是**代码版本管理工具**,GitHub 是存放代码的网站。今天掌握这些命令:
|
||||||
|
|
||||||
- `git clone`:把远程仓库复制到你的电脑
|
| 命令 | 作用 |
|
||||||
- `git add`:把改动"登记"进暂存区
|
| --- | --- |
|
||||||
- `git commit`:把暂存区的内容"存成本地记录"
|
| `git init` | 把当前文件夹变成 Git 仓库 |
|
||||||
- `git push`:把本地记录**上传**到远程仓库(**需要仓库写权限**)
|
| `git status` | 查看当前状态(改了哪些文件) |
|
||||||
|
| `git add hello.py` | 把文件"登记"进暂存区(`git add .` 表示全部) |
|
||||||
> 注意:这个仓库属于爱特工作室(组织),**只有组织成员能 push**。
|
| `git commit -m "说明"` | 把暂存区内容存成本地记录 |
|
||||||
> 你们平时交作业**不用 push**,而是把代码/截图贴在**对应日期的工单评论**里——和游戏部每日一题一样。
|
| `git branch -M main` | 把默认分支命名为 `main` |
|
||||||
> 所以今天 push 失败不要慌,这不是你的问题,按下面的任务走就对了。
|
| `git remote add origin <仓库地址>` | 关联远程仓库(`origin` 是它的名字) |
|
||||||
|
| `git push -u origin main` | 首次推送到远程(`-u` 记住关联,之后直接 `git push`) |
|
||||||
|
|
||||||
## 先学(教程)
|
## 先学(教程)
|
||||||
|
|
||||||
- 菜鸟教程 Git:https://www.runoob.com/git/git-tutorial.html
|
- 廖雪峰 Git 教程(重点看"远程仓库"和"添加远程库",我们和教程做一模一样的事):https://liaoxuefeng.com/books/git/remote/
|
||||||
- B站(零基础保姆级,看 1~6 讲即可:核心概念 / 区域 / 远程仓库):https://www.bilibili.com/video/BV1wJ4m1u7te/
|
- GitHub 官方文档·推送提交到远程仓库:https://docs.github.com/zh/get-started/using-git/pushing-commits-to-a-remote-repository
|
||||||
- 备选(含 GitLab 上手,和我们用的平台很像):https://www.bilibili.com/video/BV1Bcm4BWE2c/
|
- 菜鸟教程 Git 基础:https://www.runoob.com/git/git-tutorial.html
|
||||||
|
|
||||||
## 任务(后做)
|
## 任务(后做)
|
||||||
|
|
||||||
1. 安装 Git:https://git-scm.com/download/win ,一路默认下一步
|
1. **注册 GitHub 账号**:打开 https://github.com → Sign up,用真实信息注册(免费),记住你的**用户名**
|
||||||
2. 打开命令行(Windows 按 Win+R 输入 `cmd`),运行 `git --version`,看到版本号即成功
|
2. **创建个人仓库**:右上角 `+` → New repository → 仓库名填 `hello-daily-challenge`
|
||||||
3. 注册/登录 https://git.itouc.cn (用你的真实姓名,学长要认人)
|
→ 选 Public → 点 Create repository(**不要在页面上勾选任何初始化选项**,保持空仓库)
|
||||||
4. 克隆本仓库到本地(命令见仓库页面 Code → Clone 的 HTTPS 地址):
|
3. 在电脑上新建文件夹 `hello-daily-challenge`,在里面新建 `hello.py`,
|
||||||
```
|
文件内容**直接写**(一个字符都不要错):
|
||||||
git clone https://git.itouc.cn/ITStudio_OUC/DailyChallenge_ProgrammingDepartment.git
|
|
||||||
```
|
|
||||||
5. 进入仓库文件夹,新建文件 `hello.py`,文件内容**直接写**(一个字符都不要错):
|
|
||||||
```python
|
```python
|
||||||
print("Hello World")
|
print("Hello World")
|
||||||
```
|
```
|
||||||
6. 在命令行体验 Git 的完整本地流程:
|
4. 在该文件夹里打开命令行,依次执行:
|
||||||
```
|
```
|
||||||
git add hello.py
|
git init
|
||||||
|
git add .
|
||||||
git commit -m "add hello world"
|
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 push`——大概率会提示没有权限被拒绝,**这很正常**,
|
> `git remote add` 那行,把"你的用户名"换成你注册时用的用户名。
|
||||||
看一眼报错长什么样,记住这种感觉即可,不要纠结。
|
5. 推送时命令行会问用户名和密码,这样填:
|
||||||
7. 运行你的程序:`python hello.py`,看到输出 `Hello World`
|
- 用户名:你的 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`。
|
||||||
|
|
||||||
## 完成标准
|
## 完成标准
|
||||||
|
|
||||||
- [ ] `git --version` 有版本号输出
|
- [ ] GitHub 账号已注册
|
||||||
|
- [ ] 个人仓库 `hello-daily-challenge` 里有 `hello.py`
|
||||||
- [ ] `python hello.py` 输出 `Hello World`
|
- [ ] `python hello.py` 输出 `Hello World`
|
||||||
- [ ] `git add` + `git commit` 成功执行
|
- [ ] 能说出来:add / commit / push 分别做了什么
|
||||||
- [ ] 能说出来:clone / add / commit / push 分别做了什么,以及 push 为什么不能用
|
|
||||||
|
|
||||||
**提交方式**:在 **Day_0 工单**(本仓库 Issues 里的第一个)下方"撰写"处,
|
**提交方式**:在 **Day_0 工单**下方"撰写"处,贴上你的 **GitHub 仓库地址**
|
||||||
贴上 `hello.py` 的代码内容 + 运行输出的**截图**,然后点击"评论"。
|
(形如 `https://github.com/你的用户名/hello-daily-challenge`),然后点击"评论"。
|
||||||
|
|||||||
Reference in New Issue
Block a user