git配置及使用


🔧 第一步:配置 Git(只需做一次)

bash 复制代码
# 设置用户名和邮箱(必须)
git config --global user.name "你的名字"
git config --global user.email "你的邮箱@example.com"

# (可选)设置默认分支名为 main
git config --global init.defaultBranch main

# (可选)启用颜色输出
git config --global color.ui auto

✅ 邮箱建议和 GitHub/GitLab 账号一致,否则提交记录无法关联。


📥 第二步:拉取代码(第一次用 clone,之后用 pull)

bash 复制代码
# 第一次:克隆仓库
git clone https://github.com/用户名/项目名.git
cd 项目名

# 以后每次开始工作前:拉最新代码
git pull

📤 第三步:修改并提交代码

bash 复制代码
# 1. 修改你的文件(用编辑器写代码)

# 2. 添加所有更改到暂存区
git add .

# 3. 提交到本地
git commit -m "简要说明你改了什么"

# 4. 推送到远程仓库
git push

⚠️ 如果 git push 失败(提示有冲突或落后):

bash 复制代码
git pull --rebase  # 先同步远程最新代码,并把你的提交"接"在后面
git push           # 再推送

✅ 完整示例(复制即用)

bash 复制代码
# 配置(首次)
git config --global user.name "Alice"
git config --global user.email "alice@example.com"

# 克隆(首次)
git clone https://github.com/Alice/my-project.git
cd my-project

# 日常开发
git pull
# ... 修改代码 ...
git add .
git commit -m "fix: 修复按钮点击无效问题"
git push

相关推荐
夏至春来-美美7 小时前
git clone报错
git
番茄不是西红柿kk15 小时前
deepseek-harness跨平台桌面端二开项目(附git仓库地址+安装包)
git·agent·codex·deepseek·deepseekharness
leoZ23119 小时前
10-Git 仓库蒸馏术:从代码仓库到 OpenClaw 虚拟人-蒸馏工具链
大数据·git·深度学习·神经网络·目标检测·elasticsearch·lstm
fpcc1 天前
工具使用—git diff命令分析说明
git·工具
console.log('npc')1 天前
Git 删除指定提交记录操作指南
git
随风丶飘1 天前
[特殊字符] 告别“update“和“fix bug“——Smart Git Commit LLM 让 AI 帮你写专业的 Git 提交信息
人工智能·git·bug
yanlaifan1 天前
git clone时候指定换行符
git
小小安于乱2 天前
解决IDEA的git插件pull代码冲突但右下角不提示消息问题
java·git·intellij-idea
ITKEY_2 天前
git 命令行操作回退到指定版本
git
New_Horizons6662 天前
Git 操作(使用git-commit-template)
git