Git 安装与配置
下载 Git 官方安装包(Windows/macOS/Linux)并运行安装程序。安装完成后,打开终端或命令行工具,配置全局用户名和邮箱:
git config --global user.name "Your Name"
git config --global user.email "your.email@example.com"
验证配置是否生效:
git config --global --list
初始化本地仓库
在项目目录下执行初始化命令,创建隐藏的 .git 文件夹:
git init
检查仓库状态(常用命令):
git status
首次提交代码
将文件添加到暂存区(. 表示所有文件):
git add .
提交到本地仓库并添加注释:
git commit -m "Initial commit"
连接远程仓库
在 GitHub/GitLab 等平台创建空仓库,获取远程地址后绑定:
git remote add origin https://github.com/username/repo.git
推送代码到远程仓库(首次需加 -u 参数):
git push -u origin main
常用基础命令速查
查看提交历史:
git log
撤销工作区修改(谨慎使用):
git checkout -- filename
克隆现有仓库:
git clone https://github.com/username/repo.git
899

被折叠的 条评论
为什么被折叠?



