Git命令

配置用户名和邮箱

复制代码
git config --global user.name "Your Name"
git config --global user.email "youremail@example.com"

查看 Git 配置信息

复制代码
git config --list

初始化 Git 仓库

复制代码
git init

克隆远程仓库

复制代码
git clone <repository-url>

查看工作区状态

复制代码
git status

将新文件添加到暂存区

复制代码
git add <file>

将当前目录下的所有修改添加到暂存区

复制代码
git add .

提交暂存区中的更改并附加注释

复制代码
git commit -m "Commit message"

跳过暂存区直接提交

复制代码
git commit -a -m "Commit message"

删除文件并从暂存区移除

复制代码
git rm <file>

移动或重命名文件

复制代码
git mv <old_name> <new_name>

查看提交历史

复制代码
git log

以简洁格式显示提交历史

复制代码
git log --oneline

显示指定文件的修改历史

复制代码
git log -p <file>

图形化展示所有分支提交历史

复制代码
git log --graph --all --oneline

查看本地分支

复制代码
git branch

创建一个新分支

复制代码
git branch <branch_name>

切换到指定分支

复制代码
git checkout <branch_name>

创建并切换到新分支

复制代码
git checkout -b <branch_name>

将指定分支合并到当前分支

复制代码
git merge <branch_name>

删除本地分支

复制代码
git branch -d <branch_name>

强制删除未合并的分支

复制代码
git branch -D <branch_name>

查看远程分支

复制代码
git branch -r

列出远程仓库的 URL

复制代码
git remote -v

添加一个远程仓库

复制代码
git remote add <name> <url>

删除远程仓库

复制代码
git remote remove <name>

将本地分支推送到远程分支

复制代码
git push <remote> <branch>

拉取并合并远程分支的代码

复制代码
git pull <remote> <branch>

下载远程分支的更新

复制代码
git fetch <remote>

推送标签到远程

复制代码
git push <remote> --tags
相关推荐
leoZ2316 小时前
Git 集成实战完全指南(三):自动化 Commit 与 PR
大数据·git·elasticsearch
国服第二切图仔9 小时前
002-Claude Code 项目解读:入口与启动流程
linux·git·ubuntu
天空'之城9 小时前
VS Code Git 工作树:告别频繁切分支,实现多分支并行开发实战方案
git·vscode·版本控制·嵌入式开发·开发效率·worktree·多分支管理
程序员爱德华11 小时前
VSCode git/gerrit解冲突
git·vscode·gerrit
leoZ23120 小时前
Git 集成实战完全指南(二):智能分支管理
大数据·git·elasticsearch
qq_452396231 天前
第六篇:《GitLab CI 进阶:多环境部署与环境变量管理》
git·ci/cd·gitlab
有想法的py工程师1 天前
GPG 密钥迁移指南:多私钥备份、批量导入与自动信任
git·github
浮江雾1 天前
Flutter第五节------Flutter开发环境配置与项目创建指南
开发语言·前端·git·学习·flutter·入门·函数
aramae1 天前
C++11:现代C++的里程碑
c语言·开发语言·c++·windows·git·后端
BerryS3N1 天前
VS Code Git 工作树:解锁多分支并行开发新体验
大数据·git·elasticsearch