关于 Git 与 GitHub:初学者指南——关系、安装、链接两者并启动
Source: Dev.to
Introduction: Understanding Git and GitHub
Git 是一种流行的版本控制系统,用于跟踪代码更改、促进开发者之间的协作,并记录每一次更改的作者。
GitHub 是一个专有平台,用于托管 Git 仓库。它在此基础上添加了访问控制、问题跟踪、功能请求、任务管理、持续集成以及每个项目的 wiki 等功能。
Step 1: Opening a GitHub Account
在 GitHub 上创建一个免费账户:
Step 2: Downloading Git Bash and Launching It
从官方网站下载最新的 Git for Windows(其中包含 Git Bash):
安装完成后,启动 Git Bash 并验证版本:

Step 3: Git Configuration – Set Identity
使用与你的 GitHub 账户相同的用户名和邮箱配置 Git:

常用命令(在 Git Bash 中运行):
git config --global user.name "Your GitHub Username"
git config --global user.email "you@example.com"
Step 4: Confirm the Configured Identity
验证 Git 是否已存储正确的信息:

git config --list
注意:确保邮箱与用于注册 GitHub 的邮箱一致。
Step 5: Generating an SSH Key – Connecting Git to GitHub
SSH 密钥用于在你的机器与 GitHub 之间进行身份验证,允许在不反复输入密码的情况下安全通信。
生成一个新的 SSH 密钥(如果尚未拥有),并将其添加到 ssh‑agent:
ssh-keygen -t ed25519 -C "you@example.com"
# 按提示操作;按 Enter 接受默认文件位置。
eval "$(ssh-agent -s)"
ssh-add ~/.ssh/id_ed25519
生成的公钥大致如下图所示:

Step 6: Add the SSH Key to GitHub
- 复制公钥文件 (
~/.ssh/id_ed25519.pub) 的内容。 - 在 GitHub 中,进入 Settings → SSH and GPG keys → New SSH key。
- 粘贴密钥,填写易于辨认的标题,然后保存。
密钥添加成功后,GitHub 会发送确认邮件。

Step 7: Open a Project Folder on GitHub
现在你可以克隆已有仓库或创建新仓库,然后使用 Git Bash 在本地进行操作。例如,克隆仓库的命令如下:
git clone git@github.com:YourUsername/your-repo.git
一切就绪,你可以开始跟踪更改、推送提交,并通过 GitHub 与他人协作!