销售:050-1791-1110

GitHub 基础操作

什么是 GitHub?

GitHub 是全球最大的代码托管平台,基于 Git 版本控制系统。你可以在上面存储代码、协作开发、提交 Bug 报告等。

注册与设置

  1. 访问 github.com 注册免费账号
  2. 安装 Git:sudo apt install git
  3. 配置用户信息:
    git config --global user.name "你的名字"
    git config --global user.email "your@email.com"
  4. 配置 SSH 密钥:
    ssh-keygen -t ed25519
    cat ~/.ssh/id_ed25519.pub
    # 将公钥添加到 GitHub → Settings → SSH Keys

基本工作流

# 克隆远程仓库
git clone git@github.com:username/repo.git
cd repo

# 创建分支
git checkout -b feature/my-feature

# 修改代码后
git add .
git commit -m "feat: add new feature"

# 推送到远程
git push origin feature/my-feature

# 在 GitHub 上创建 Pull Request

常用命令速查

命令 说明
git status 查看当前状态
git log --oneline 查看提交历史
git diff 查看未暂存的修改
git stash 暂存当前修改
git pull 拉取远程更新
git merge main 合并 main 分支
git rebase main 变基到 main

GitHub 特色功能

  • Issues:跟踪 Bug 和需求
  • Pull Requests:代码评审与合并
  • Actions:CI/CD 自动化
  • Pages:免费静态网站托管
  • Copilot:AI 编程助手
滚动至顶部