Github使用教程

第一部分:从 GitHub 下载项目到本地

方法一:克隆到本地(推荐)

步骤:
cpp 复制代码
第1步:打开你的 GitHub 仓库
https://github.com/fengfengfff/IntelligentCommunity

第2步:点击绿色的 "Code" 按钮
    ↓
第3步:选择 "Local" → "HTTPS"
    ↓
第4步:复制仓库地址
https://github.com/fengfengfff/IntelligentCommunity.git

第5步:打开 Git Bash(或终端)
    ↓
第6步:进入你想存放项目的目录
cd /d/项目存放目录

第7步:执行克隆命令
git clone https://github.com/fengfengfff/IntelligentCommunity.git

第8步:等待下载完成
    ↓
第9步:进入项目目录
cd IntelligentCommunity

第10步:用 Qt Creator 打开 IntelligentCommunity.pro

方法二:下载 ZIP 压缩包

步骤:
cpp 复制代码
第1步:打开你的 GitHub 仓库
https://github.com/fengfengfff/IntelligentCommunity

第2步:点击绿色的 "Code" 按钮
    ↓
第3步:选择 "Download ZIP"
    ↓
第4步:浏览器会自动下载一个 ZIP 文件
    ↓
第5步:解压 ZIP 文件到你的工作目录
    ↓
第6步:用 Qt Creator 打开 IntelligentCommunity.pro

方法三:在另一台电脑上克隆

cpp 复制代码
# 在新电脑上
git clone https://github.com/fengfengfff/IntelligentCommunity.git
cd IntelligentCommunity
# 然后用 Qt Creator 打开项目

第二部分:GitHub 完整使用教程

1. GitHub 核心概念

概念 说明
Repository(仓库) 存放项目代码的地方
Branch(分支) 代码的不同版本线
Commit(提交) 保存代码变更的快照
Push(推送) 上传本地提交到 GitHub
Pull(拉取) 下载 GitHub 上的更新
Clone(克隆) 复制整个仓库到本地
Fork(复刻) 复制别人的仓库到自己的账号
Pull Request(PR) 请求合并代码的请求

2. 日常操作流程

流程 A:首次克隆项目
cpp 复制代码
# 1. 克隆仓库
git clone https://github.com/用户名/仓库名.git

# 2. 进入项目目录
cd 仓库名

# 3. 查看远程仓库
git remote -v

# 4. 查看分支
git branch -a
流程 B:修改代码后提交
cpp 复制代码
# 1. 查看修改状态
git status

# 2. 添加修改到暂存区
git add .

# 3. 提交到本地
git commit -m "feat: 添加新功能"

# 4. 推送到 GitHub
git push
流程 C:从 GitHub 拉取更新
cpp 复制代码
# 拉取最新代码
git pull

# 或者
git fetch
git merge origin/main

3. 分支管理

创建和切换分支
cpp 复制代码
# 查看所有分支
git branch

# 创建新分支
git branch feature/new-feature

# 切换分支
git checkout feature/new-feature

# 创建并切换(一步完成)
git checkout -b feature/new-feature

# 切换到 main 分支
git checkout main
合并分支
cpp 复制代码
# 1. 切换到目标分支
git checkout main

# 2. 合并分支
git merge feature/new-feature

# 3. 推送
git push
删除分支
cpp 复制代码
# 删除本地分支
git branch -d feature/new-feature

# 删除远程分支
git push origin --delete feature/new-feature

4. Pull Request(拉取请求)

场景:贡献代码到别人的仓库
cpp 复制代码
第1步:Fork 别人的仓库到你的账号
    ↓
第2步:克隆你 Fork 的仓库到本地
    ↓
第3步:创建新分支,修改代码
    ↓
第4步:推送你的分支
    ↓
第5步:在 GitHub 上点击 "New Pull Request"
    ↓
第6步:选择 base(目标仓库)和 compare(你的分支)
    ↓
第7步:填写描述,点击 "Create Pull Request"
    ↓
第8步:等待仓库所有者审核和合并

5. 常用 Git 命令速查

命令 说明
git init 初始化 Git 仓库
git clone URL 克隆远程仓库
git status 查看文件状态
git add . 添加所有文件到暂存区
git add 文件名 添加指定文件
git commit -m "信息" 提交到本地仓库
git push 推送到远程仓库
git pull 拉取远程更新
git fetch 获取远程更新(不合并)
git branch 查看本地分支
git checkout 分支名 切换分支
git checkout -b 分支名 创建并切换分支
git merge 分支名 合并分支
git remote -v 查看远程仓库地址
git log --oneline 查看提交历史
git diff 查看修改内容
git reset --hard HEAD~1 撤销最近一次提交
git stash 临时保存修改

💡 第三部分:GitHub 小技巧

🏷️ 1. 设置默认分支

cpp 复制代码
仓库页面 → Settings → Branches → Default branch
→ 选择 main 或 master → Update

2. 创建 .gitignore 模板

GitHub 提供了常见语言的 .gitignore 模板:

cpp 复制代码
创建仓库时 → Add .gitignore → 选择 "C++" 或 "Qt"

3. 给项目 Star(收藏)

cpp 复制代码
点击仓库右上角的 ⭐ Star 按钮
可以收藏喜欢的项目

4. 完善 README.md

好的 README 包含:

  • 项目名称和描述

  • 功能截图

  • 技术栈

  • 安装和使用说明

  • 贡献指南

  • 许可证

5. GitHub 搜索技巧

cpp 复制代码
# 按语言搜索
language:cpp qt

# 按 Stars 搜索
stars:>1000

# 按更新时间搜索
pushed:>2026-01-01

# 组合搜索
qt language:cpp stars:>500

6. GitHub 仓库快捷键

快捷键 功能
t 快速查找文件
w 切换分支
s 聚焦搜索框
l 跳转到文件列表
/ 聚焦搜索框

7. 在 README 中添加图片

cpp 复制代码
![图片描述](https://github.com/用户名/仓库名/raw/main/图片路径.png)

8. 创建组织(Organization)

适合团队协作,可以管理多个仓库和成员:

cpp 复制代码
右上角头像 → Settings → Organizations → New organization

9. 使用 Release(发布版本)

cpp 复制代码
仓库页面 → Releases → Create a new release
→ 填写版本号(如 v1.0.0)
→ 上传编译好的程序(.exe)
→ 点击 Publish release

10. GitHub 保护分支

cpp 复制代码
仓库页面 → Settings → Branches → Add rule
→ 输入分支名(如 main)
→ 勾选 "Require pull request reviews"
→ 勾选 "Require status checks to pass"
→ 点击 Create

第四部分:你的项目在面试中展示

面试时这样说:

"我把这个项目托管在 GitHub 上:https://github.com/fengfengfff/IntelligentCommunity。面试官可以查看完整代码、提交历史,了解我的编码风格和项目组织能力。项目代码注释完善,采用 MVC 架构,包含 17 个功能模块,代码量 6500+ 行。"

总结

操作 命令
克隆项目 git clone URL
提交代码 git add . + git commit -m "信息" + git push
拉取更新 git pull
创建分支 git checkout -b 新分支名
合并分支 git merge 分支名
查看状态 git status
查看历史 git log --oneline

你的 GitHub 仓库:

cpp 复制代码
https://github.com/fengfengfff/IntelligentCommunity
相关推荐
天若有情6735 小时前
表面普通随机数网页,藏有隐藏后台面板,暗号解锁|Github Pages 在线演示
github
典典分享指南8 小时前
DeepSeek Harness 开源贡献手记:从 Issue 到 Merge 的完整旅程
jupyter·github·vim·idea·visual studio
峰向AI12 小时前
坚持不下去?这个 14K Star 的 App 把你的习惯变成 RPG 游戏
github
Bmob后端云12 小时前
Bmob后端云实战|Python实现SSE流式输出,给备忘录AI加上打字机效果
前端·github
峰向AI1 天前
还在手动配 SSL 证书?这个 75K Star 的 Web 服务器让 HTTPS 自动到起飞
github
Java陈序员1 天前
轻量运维面板!一款现代化的服务器控制面板工具!
运维·服务器·python·react.js·github
u1301301 天前
GitHub 热榜项目:日榜(2026-09-10)
github
用户2136863783521 天前
给 DeepSeek Harness 写了个「技能熔炉」:任何来源的 SKILL.md 一条命令装上
github
七牛开发者1 天前
告别反复调参,一个 Skill 让 AI 掌握论文图的视觉语法:以 DeepSeek V4.1 Flash 论文图为例
github·agent·deepseek
简创AIGC陶先生1 天前
【直播切片工作台】第11章:剪辑项目模型 VideoProject
github