Git & GitHub:面向数据专业人士的版本控制入门指南

发布: (2026年1月18日 GMT+8 05:39)
2 min read
原文: Dev.to

Source: Dev.to

安装 Git

Windows 用户

  1. 访问 Git for Windows 下载页面
  2. 下载 Windows 安装程序。
  3. 使用以下推荐设置运行安装程序:
    • 选择 “仅在 Git Bash 中使用 Git”。
    • 选择 “Checkout Windows‑style, commit Unix‑style line endings”。
    • 使用 MinTTY 作为终端仿真器。
    • 启用 文件系统缓存。

macOS 用户

brew install git

Linux 用户

# Debian/Ubuntu
sudo apt-get install git

# CentOS/Fedora
sudo yum install git

验证安装

git --version

配置 Git

git config --global user.name "Your Name"
git config --global user.email "your.email@example.com"

生成 SSH 密钥

ssh-keygen -t rsa -b 4096 -C "your.email@example.com"
  • Enter 接受默认文件位置。
  • 在提示时创建密码短语。

查看公钥:

cat ~/.ssh/id_rsa.pub

复制全部输出内容。

将 SSH 密钥添加到 GitHub

  1. 前往 GitHub → Settings → SSH and GPG keys → New SSH key
  2. 粘贴你的密钥并保存。

测试连接

ssh -T git@github.com

你应该会看到类似以下的信息:
Hi username! You've successfully authenticated...

了解版本控制:是什么以及为什么

什么是版本控制?

把它想象成代码的时间机器。每一次更改都会被保存,这样你可以:

  • 跟踪是谁做了哪些更改。
  • 回退到之前的版本。
  • 在不破坏主代码的情况下开发新功能。
  • 在协作时避免覆盖他人的工作。

数据专业人员为何需要 Git

  • 可重复性: 精确记录哪一版本的代码产生了哪些结果。
  • 协作: 多位团队成员可以同时在同一项目上工作。
  • 实验性: 试验新方法而不必担心破坏已有代码。
  • 文档化: 提交信息说明更改的原因。
Back to Blog

相关文章

阅读更多 »

Git 和 GitHub 初学者指南

如果你曾经把文件保存为 final_project.py,然后是 final_project_v2.py,最终是 final_project_v3.py,你就已经体验了手动版的版本控制。

Git 与 GitHub:初学者指南

Git 和 GitHub 的封面图片:初学者指南 https://media2.dev.to/dynamic/image/width=1000,height=420,fit=cover,gravity=auto,format=auto/https%3...