git常用命令

分支

删除分支

// 删除本地分支

git branch -d localBranchName

// 删除远程分支

git push origin --delete remoteBranchName

切换分支

//以远程分支为基础新建一个分支,并切换到该分支

git checkout -b [branch] origin/[remote-branch]

//切换到指定分支,并更新工作区

git checkout [branch-name]

//切换到指定分支

git switch [branch-name]

新建分支

// 新建一个分支,但依然停留在当前分支

git branch [branch-name]

//新建一个分支,与指定的远程分支建立追踪关系

git branch --track [branch] [remote-branch]

合并分支

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

git merge [branch]

列出分支

// 列出所有本地分支

git branch

// 列出所有远程分支

git branch -r

// 列出所有本地分支和远程分支

git branch -a

增删文件

git add

// 添加当前目录的所有文件到暂存区

git add .

git rm

删除工作区文件,并且将这次删除放入暂存区

$ git rm [file1] [file2] ...

递归删除git中的跟踪索引文件,但该文件会保留在工作区

$ git rm --cached -r [file]

提交

// 提交暂存区到仓库区

git commit -m "提交信息"

// 提交所有变化到仓库区

git commit -a

// 提交时显示所有diff信息

git commit -v

相关推荐
淘矿人1 天前
从0到1:用Claude启动你的第一个项目
开发语言·人工智能·git·python·github·php·pygame
lpfasd1231 天前
Git/Gitee/GitHub 3 个安全凭证详解
git·gitee·github
李日灐1 天前
< 7 > Linux 开发工具:git 版本控制器 和 cgdb/gdb 调试器
linux·运维·服务器·开发语言·git·调试器·gdb/cgdb
Gust of wind1 天前
idea结合git和Gitee的初步使用
git·gitee·intellij-idea
夜七少eleanor1 天前
【Git】2026全图文详解安装教程
git
海边的Kurisu1 天前
从零开始的Git生活 | 刚实习同学的噩梦 And 参与开源不可缺的一环
git·生活
不老刘1 天前
Git Cherry-Pick:微前端架构下的“精准医疗”与最佳实践
前端·git
爬楼的猪2 天前
Git Folder Dashboard
git
Uncertainty!!2 天前
claude code中添加skills自动生成git commit信息
git·git commit·claude code
FserSuN2 天前
Git Worktree 使用学习
git·学习