🚀 Git 与 GitHub 入门指南:初学者指南
发布: (2026年1月18日 GMT+8 13:50)
2 min read
原文: Dev.to
Source: Dev.to
什么以及为什么:Git 与 GitHub
- 当出现问题时可以回到之前的版本。
- 与团队成员协作时不会相互覆盖代码。
- 查看是谁在何时做了哪些更改。
GitHub 是一个基于云的平台,托管 Git 仓库,并提供协作、问题跟踪和代码审查等额外工具。它提供远程仓库托管,并与 Git 集成,使团队协作更便捷。
第一步:创建项目
1. 跟踪更改
git init # Initialize a new repository
git status # See untracked or modified files
git add # Stage selected changes
git commit -m "Message" # Create a snapshot with a descriptive label
2. 将代码推送到 GitHub
-
在 GitHub.com 上创建一个新仓库。
-
复制仓库 URL,例如
https://github.com/your-username/my-project.git。 -
将本地文件夹关联到远程仓库(只需运行一次):
git remote add origin https://github.com/your-username/my-project.git -
推送代码:
git push -u origin main
3. 从 GitHub 拉取代码
git pull origin main
基本工作流概览
-
通过网页界面在 GitHub 上创建一个新仓库。
-
将其克隆到本地机器:
git clone https://github.com/your-username/my-project.git -
在工作目录中进行更改。
-
暂存更改:
git add . -
使用说明提交:
git commit -m "Describe your changes" -
推送到 GitHub:
git push -u origin main
祝编码愉快,愿你的代码始终得到完美的版本控制! ✨💻