From 8e683413e1b6e098f36f1e12dad677d96213f89a Mon Sep 17 00:00:00 2001 From: lkjing2021345 <1908499668@qq.com> Date: Sat, 22 Aug 2026 21:33:07 +0800 Subject: [PATCH] =?UTF-8?q?Update=20Day=5F0:=20=E6=94=B9=E4=B8=BA=E6=B3=A8?= =?UTF-8?q?=E5=86=8CGitHub=E5=B9=B6=E6=8E=A8=E9=80=81=E5=88=B0=E4=B8=AA?= =?UTF-8?q?=E4=BA=BA=E4=BB=93=E5=BA=93,=20=E5=B7=A5=E5=8D=95=E4=BA=A4?= =?UTF-8?q?=E4=BB=93=E5=BA=93=E5=9C=B0=E5=9D=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Day_0/README.md | 78 ++++++++++++++++++++++++++++--------------------- 1 file changed, 45 insertions(+), 33 deletions(-) diff --git a/Day_0/README.md b/Day_0/README.md index e3720df..faacc7d 100644 --- a/Day_0/README.md +++ b/Day_0/README.md @@ -1,55 +1,67 @@ -# Day_0 · Git 入门与 Hello World(第零节) +# Day_0 · 注册 GitHub,把 Hello World 推送到自己的仓库(第零节) -> 预计耗时:20~30 分钟 -> 这一节不写任何难代码,只做三件事:**会用 Git、会克隆仓库、会提交作业**。 +> 预计耗时:25~30 分钟 +> 今天做四件事:**注册 GitHub、建自己的仓库、用命令行把代码推上去、在工单里交仓库地址**。 +> 推送的目标是你**自己的 GitHub 仓库**,不是工作室的仓库(工作室仓库只有学长能 push)。 ## 今日知识点 -Git 是一个**代码版本管理工具**。今天只需要掌握四个动作: +Git 是**代码版本管理工具**,GitHub 是存放代码的网站。今天掌握这些命令: -- `git clone`:把远程仓库复制到你的电脑 -- `git add`:把改动"登记"进暂存区 -- `git commit`:把暂存区的内容"存成本地记录" -- `git push`:把本地记录**上传**到远程仓库(**需要仓库写权限**) - -> 注意:这个仓库属于爱特工作室(组织),**只有组织成员能 push**。 -> 你们平时交作业**不用 push**,而是把代码/截图贴在**对应日期的工单评论**里——和游戏部每日一题一样。 -> 所以今天 push 失败不要慌,这不是你的问题,按下面的任务走就对了。 +| 命令 | 作用 | +| --- | --- | +| `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://www.runoob.com/git/git-tutorial.html -- B站(零基础保姆级,看 1~6 讲即可:核心概念 / 区域 / 远程仓库):https://www.bilibili.com/video/BV1wJ4m1u7te/ -- 备选(含 GitLab 上手,和我们用的平台很像):https://www.bilibili.com/video/BV1Bcm4BWE2c/ +- 廖雪峰 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 ## 任务(后做) -1. 安装 Git:https://git-scm.com/download/win ,一路默认下一步 -2. 打开命令行(Windows 按 Win+R 输入 `cmd`),运行 `git --version`,看到版本号即成功 -3. 注册/登录 https://git.itouc.cn (用你的真实姓名,学长要认人) -4. 克隆本仓库到本地(命令见仓库页面 Code → Clone 的 HTTPS 地址): - ``` - git clone https://git.itouc.cn/ITStudio_OUC/DailyChallenge_ProgrammingDepartment.git - ``` -5. 进入仓库文件夹,新建文件 `hello.py`,文件内容**直接写**(一个字符都不要错): +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") ``` -6. 在命令行体验 Git 的完整本地流程: +4. 在该文件夹里打开命令行,依次执行: ``` - git add hello.py + 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 push`——大概率会提示没有权限被拒绝,**这很正常**, - 看一眼报错长什么样,记住这种感觉即可,不要纠结。 -7. 运行你的程序:`python hello.py`,看到输出 `Hello World` + > `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`。 ## 完成标准 -- [ ] `git --version` 有版本号输出 +- [ ] GitHub 账号已注册 +- [ ] 个人仓库 `hello-daily-challenge` 里有 `hello.py` - [ ] `python hello.py` 输出 `Hello World` -- [ ] `git add` + `git commit` 成功执行 -- [ ] 能说出来:clone / add / commit / push 分别做了什么,以及 push 为什么不能用 +- [ ] 能说出来:add / commit / push 分别做了什么 -**提交方式**:在 **Day_0 工单**(本仓库 Issues 里的第一个)下方"撰写"处, -贴上 `hello.py` 的代码内容 + 运行输出的**截图**,然后点击"评论"。 +**提交方式**:在 **Day_0 工单**下方"撰写"处,贴上你的 **GitHub 仓库地址** +(形如 `https://github.com/你的用户名/hello-daily-challenge`),然后点击"评论"。