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

相关推荐
Unity粉末状在校生2 小时前
Git解决fatal: Could not read from remote repository.的问题
git
少年攻城狮2 小时前
Obsidian系列---【如何使用obsidian同步到git?】
git
do better myself5 小时前
网站源码如何部署和加入GIT仓库的
git
爱学英语的程序员7 小时前
Git 提交 LF will be replaced by CRLF the next time Git touches it 报错
git
qq_339191148 小时前
服务器git pull每次都要输入密码,linux 设置git登录,linux设置git只输入一次账户密码
git
一颗小行星!14 小时前
快速理解 Git submodule
git
A-Jie-Y16 小时前
Git基础-核心概念与常用命令
git
夜珀17 小时前
Git基础修炼手册:在AtomGit上玩转版本控制
git
golang学习记17 小时前
Zed IDE官宣新招:Git Graph 正式支持!
ide·git
要记得喝水17 小时前
适用于 Git Bash 的脚本,批量提交和推送多个仓库的修改
git·elasticsearch·bash