278 字
1 分钟
git常用命令
2026-02-22
命令描述
git init初始化新仓库
git add .添加所有更改到暂存区
git add <file>添加指定文件到暂存区
git commit -m "信息"提交暂存区文件到仓库
git log --oneline查看简洁提交历史
git checkout <commit-hash>切换到指定提交(只读)
git remote -v列出远程仓库及地址
git branch列出本地分支
git checkout <branch-name>切换到指定分支
git branch -m <旧名> <新名>重命名本地分支
git merge <branch-name>合并指定分支到当前分支
git pull origin <branch-name>拉取并合并远程分支
git branch -d <branch-name>删除已合并分支
git branch -D <branch-name>强制删除本地分支
git branch -M main修改本地分支名字
git remote add <别名> <地址>添加远程仓库
git push origin <branch-name>推送当前分支到远程
git push -u origin <branch-name>推送并设置上游
git push origin <branch-name> --force强制推送覆盖远程(慎用)
git remote set-url origin <地址>修改远程仓库地址
git remote rm <别名>删除远程仓库关联
git push origin --delete <branch-name>删除远程分支
git常用命令
https://fuwari.vercel.app/posts/git常用命令/
作者
vali
发布于
2026-02-22
许可协议
CC BY-NC-SA 4.0